peasant answer at different speed

This commit is contained in:
Samir Badi 2024-11-11 12:38:38 -05:00
parent 4304c31b1a
commit 1a34a1c036
10 changed files with 122 additions and 92 deletions

View File

@ -9,8 +9,9 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 3614258387417921825} - component: {fileID: 3614258387417921825}
- component: {fileID: 774219910790536021}
m_Layer: 0 m_Layer: 0
m_Name: NPC m_Name: Peasant
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -32,6 +33,22 @@ Transform:
- {fileID: 716864403826928654} - {fileID: 716864403826928654}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &774219910790536021
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2684113167729998087}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c6861fab896dc3b44bad96b7fb1e4891, type: 3}
m_Name:
m_EditorClassIdentifier:
answers: []
initTime: 20
minTimePerQuestion: 5
maxTimePerQuestion: 18
--- !u!1 &5739709613417327085 --- !u!1 &5739709613417327085
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -237,7 +237,7 @@ GameObject:
m_Component: m_Component:
- component: {fileID: 54002814} - component: {fileID: 54002814}
m_Layer: 0 m_Layer: 0
m_Name: NPCs m_Name: Peasant
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -264,7 +264,6 @@ Transform:
- {fileID: 266640701} - {fileID: 266640701}
- {fileID: 187840932} - {fileID: 187840932}
- {fileID: 668048816} - {fileID: 668048816}
- {fileID: 2076373778}
m_Father: {fileID: 1958973072} m_Father: {fileID: 1958973072}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &81375270 --- !u!1 &81375270
@ -514,7 +513,7 @@ PrefabInstance:
- target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
propertyPath: m_Name propertyPath: m_Name
value: NPC (5) value: Zoe
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
@ -765,10 +764,25 @@ PrefabInstance:
serializedVersion: 3 serializedVersion: 3
m_TransformParent: {fileID: 54002814} m_TransformParent: {fileID: 54002814}
m_Modifications: m_Modifications:
- target: {fileID: 774219910790536021, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: initTime
value: 2
objectReference: {fileID: 0}
- target: {fileID: 774219910790536021, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: maxTimePerQuestion
value: 1
objectReference: {fileID: 0}
- target: {fileID: 774219910790536021, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: minTimePerQuestion
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
propertyPath: m_Name propertyPath: m_Name
value: NPC (4) value: Amelia
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
@ -842,7 +856,7 @@ PrefabInstance:
- target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
propertyPath: m_Name propertyPath: m_Name
value: NPC (2) value: Oliver
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
@ -2047,7 +2061,7 @@ PrefabInstance:
- target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
propertyPath: m_Name propertyPath: m_Name
value: NPC (7) value: Caleb
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
@ -3013,7 +3027,7 @@ PrefabInstance:
- target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
propertyPath: m_Name propertyPath: m_Name
value: NPC (3) value: Ethan
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
@ -3371,7 +3385,7 @@ PrefabInstance:
- target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
propertyPath: m_Name propertyPath: m_Name
value: NPC (1) value: Sophia
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
@ -3607,7 +3621,7 @@ PrefabInstance:
- target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
propertyPath: m_Name propertyPath: m_Name
value: NPC (8) value: Layla
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
@ -3880,6 +3894,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 45f6ccbbf842ceb47bfe1cc19085daa0, type: 3} m_Script: {fileID: 11500000, guid: 45f6ccbbf842ceb47bfe1cc19085daa0, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
answers: []
--- !u!114 &1721698432 --- !u!114 &1721698432
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -3945,6 +3960,7 @@ MonoBehaviour:
- {fileID: 233852084, guid: 19a8aecd158cac04fb8bb6de1e21ffaa, type: 3} - {fileID: 233852084, guid: 19a8aecd158cac04fb8bb6de1e21ffaa, type: 3}
seed: 0 seed: 0
randomGeneration: 1 randomGeneration: 1
correctAnswer: []
--- !u!1 &1839156921 --- !u!1 &1839156921
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -4726,7 +4742,7 @@ PrefabInstance:
- target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
propertyPath: m_Name propertyPath: m_Name
value: NPC (6) value: Lucas
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754, - target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3} type: 3}
@ -4789,80 +4805,6 @@ Transform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 2038879509} m_PrefabInstance: {fileID: 2038879509}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1001 &2076373777
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 54002814}
m_Modifications:
- target: {fileID: 2684113167729998087, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: m_Name
value: NPC (9)
objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: m_LocalPosition.z
value: 13.25
objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: m_LocalRotation.w
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: m_LocalRotation.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 180
objectReference: {fileID: 0}
- target: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 58a9a466f0501ce4d8388102500b1754, type: 3}
--- !u!4 &2076373778 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 3614258387417921825, guid: 58a9a466f0501ce4d8388102500b1754,
type: 3}
m_PrefabInstance: {fileID: 2076373777}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &3500289701967161187 --- !u!1001 &3500289701967161187
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -1,9 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using GameOff.Quiz;
using UnityEngine; using UnityEngine;
using Random = System.Random; using Random = System.Random;
namespace GameOff.Quiz namespace GameOff.Core
{ {
[DefaultExecutionOrder(-60)] [DefaultExecutionOrder(-60)]
public class QuizHandler : MonoBehaviour public class QuizHandler : MonoBehaviour
@ -14,7 +15,8 @@ namespace GameOff.Quiz
[SerializeField] private List<Sprite> questionVisual; [SerializeField] private List<Sprite> questionVisual;
[SerializeField] private int seed; [SerializeField] private int seed;
[SerializeField] private bool randomGeneration; [SerializeField] private bool randomGeneration;
[SerializeField] private string[] correctAnswer;
private readonly List<string> ChoicePossibles = new List<string>() { "a", "b", "c", "d", "e", "f" }; private readonly List<string> ChoicePossibles = new List<string>() { "a", "b", "c", "d", "e", "f" };
private Random _random; private Random _random;
@ -44,8 +46,9 @@ namespace GameOff.Quiz
private void GenerateQuiz() private void GenerateQuiz()
{ {
_questionInfos = new List<QuestionInfo>(); _questionInfos = new List<QuestionInfo>();
correctAnswer = new string[questionAmount];
for (int i = 1; i <= questionAmount; i++) for (int i = 0; i < questionAmount; i++)
{ {
int amount = _random.Next(2, ChoicePossibles.Count); int amount = _random.Next(2, ChoicePossibles.Count);
string answer = ChoicePossibles[_random.Next(amount)]; string answer = ChoicePossibles[_random.Next(amount)];
@ -53,12 +56,15 @@ namespace GameOff.Quiz
for (int x = 0; x < amount; x++) for (int x = 0; x < amount; x++)
tmp.Add(ChoicePossibles[x]); tmp.Add(ChoicePossibles[x]);
_questionInfos.Add(new QuestionInfo(i, questionVisual[_random.Next(questionVisual.Count)], tmp, answer));
_questionInfos.Add(new QuestionInfo(i + 1, questionVisual[_random.Next(questionVisual.Count)], tmp, answer));
correctAnswer[i] = tmp[_random.Next(amount)];
} }
} }
public string GetAnswerAtIndex(int index) => correctAnswer[index];
public List<QuestionInfo> QuestionInfos => _questionInfos; public List<QuestionInfo> QuestionInfos => _questionInfos;
public int QuestionAmount => questionAmount; public int QuestionAmount => questionAmount;
} }
} }

View File

@ -1,7 +1,7 @@
using System; using GameOff.Quiz;
using UnityEngine; using UnityEngine;
namespace GameOff.Quiz namespace GameOff.Core
{ {
public abstract class QuizTaker: MonoBehaviour public abstract class QuizTaker: MonoBehaviour
{ {

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0d71d71ca8238454fabed5ca071e4807
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,46 @@
using System;
using GameOff.Core;
using GameOff.Quiz;
using UnityEngine;
using Random = UnityEngine.Random;
namespace GameOff.Peasant
{
public class PeasantMain : QuizTaker
{
[SerializeField] private float initTime = 20f;
[SerializeField] private float minTimePerQuestion = 5f;
[SerializeField] private float maxTimePerQuestion = 18f;
private int _indexQuestion;
private float _answerTimer;
protected override void Start()
{
base.Start();
_answerTimer = initTime + RandomQuestionTimer();
}
private void Update()
{
_answerTimer -= Time.deltaTime;
if (_answerTimer <= 0)
{
answers[_indexQuestion] = QuizHandler.Instance.GetAnswerAtIndex(_indexQuestion);
_answerTimer = RandomQuestionTimer();
_indexQuestion++;
if (_indexQuestion >= answers.Length)
enabled = false;
}
}
private float RandomQuestionTimer()
{
return Random.Range(minTimePerQuestion, maxTimePerQuestion);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c6861fab896dc3b44bad96b7fb1e4891
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: