mirror of
https://github.com/ConjureETS/GameOff2024.git
synced 2026-03-24 05:00:59 +00:00
Save player choice
This commit is contained in:
parent
6de15f94f7
commit
4304c31b1a
@ -1630,10 +1630,10 @@ MonoBehaviour:
|
||||
m_Content: {fileID: 297350527}
|
||||
m_Horizontal: 0
|
||||
m_Vertical: 1
|
||||
m_MovementType: 1
|
||||
m_MovementType: 2
|
||||
m_Elasticity: 0.1
|
||||
m_Inertia: 1
|
||||
m_DecelerationRate: 0.135
|
||||
m_DecelerationRate: 25
|
||||
m_ScrollSensitivity: 50
|
||||
m_Viewport: {fileID: 0}
|
||||
m_HorizontalScrollbar: {fileID: 0}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using GameOff.Core;
|
||||
using GameOff.UI.Quiz;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameOff.Basic
|
||||
@ -10,6 +11,7 @@ namespace GameOff.Basic
|
||||
private void Awake()
|
||||
{
|
||||
PlayerMain.ClearStaticVariables();
|
||||
QuestionUI.ClearStaticVariables();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using GameOff.Player;
|
||||
using GameOff.Quiz;
|
||||
using GameOff.UI.Quiz;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameOff.Core
|
||||
{
|
||||
public class PlayerMain : MonoBehaviour
|
||||
public class PlayerMain : QuizTaker
|
||||
{
|
||||
public static PlayerMain Instance { get; private set; }
|
||||
public static void ClearStaticVariables()
|
||||
@ -33,13 +35,16 @@ namespace GameOff.Core
|
||||
_inputHandler = GetComponent<PlayerInputHandler>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
protected override void Start()
|
||||
{
|
||||
_inputHandler.OnChangeState += InputHandler_OnChangeState;
|
||||
QuestionUI.OnAnyQuestionChoice += (sender, choice) => answers[choice.Index - 1] = choice.Answer;
|
||||
|
||||
_classState = new PlayerClassState();
|
||||
_quizState = new PlayerQuizState();
|
||||
_currentState = _classState;
|
||||
|
||||
base.Start();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
||||
14
Assets/Scripts/Quiz/QuestionChoice.cs
Normal file
14
Assets/Scripts/Quiz/QuestionChoice.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace GameOff.Quiz
|
||||
{
|
||||
public struct QuestionChoice
|
||||
{
|
||||
public int Index { get; private set; }
|
||||
public string Answer { get; private set; }
|
||||
|
||||
public QuestionChoice(int index, string answer)
|
||||
{
|
||||
Index = index;
|
||||
Answer = answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Quiz/QuestionChoice.cs.meta
Normal file
3
Assets/Scripts/Quiz/QuestionChoice.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d8895d53dbf4543ab3eddd7c7616285
|
||||
timeCreated: 1731344936
|
||||
@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GameOff.Quiz;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using Random = System.Random;
|
||||
|
||||
namespace GameOff.Core
|
||||
namespace GameOff.Quiz
|
||||
{
|
||||
[DefaultExecutionOrder(-60)]
|
||||
public class QuizHandler : MonoBehaviour
|
||||
@ -60,5 +58,7 @@ namespace GameOff.Core
|
||||
}
|
||||
|
||||
public List<QuestionInfo> QuestionInfos => _questionInfos;
|
||||
|
||||
public int QuestionAmount => questionAmount;
|
||||
}
|
||||
}
|
||||
14
Assets/Scripts/Quiz/QuizTaker.cs
Normal file
14
Assets/Scripts/Quiz/QuizTaker.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameOff.Quiz
|
||||
{
|
||||
public abstract class QuizTaker: MonoBehaviour
|
||||
{
|
||||
[SerializeField] protected string[] answers;
|
||||
protected virtual void Start()
|
||||
{
|
||||
answers = new string[QuizHandler.Instance.QuestionAmount];
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Quiz/QuizTaker.cs.meta
Normal file
3
Assets/Scripts/Quiz/QuizTaker.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bfaa0e61d02c43a5b4176e1b4aeb0fb7
|
||||
timeCreated: 1731343953
|
||||
@ -6,7 +6,7 @@ namespace GameOff.UI.Quiz
|
||||
{
|
||||
public class ChoiceUI: MonoBehaviour
|
||||
{
|
||||
public event EventHandler<string> OnAswerTrigger;
|
||||
public event EventHandler<string> OnAnswerTrigger;
|
||||
|
||||
[SerializeField] private Text letterText;
|
||||
[SerializeField] private Button selectButton;
|
||||
@ -17,9 +17,9 @@ namespace GameOff.UI.Quiz
|
||||
letterText.text = $"{letter}.";
|
||||
selectedVisual.SetActive(false);
|
||||
|
||||
selectButton.onClick.AddListener(() => OnAswerTrigger?.Invoke(this, letter));
|
||||
selectButton.onClick.AddListener(() => OnAnswerTrigger?.Invoke(this, letter));
|
||||
|
||||
question.OnChoiceUptade += (sender, e) => selectedVisual.SetActive(e == letter);
|
||||
question.OnChoiceUpdate += (sender, e) => selectedVisual.SetActive(e == letter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,7 +9,13 @@ namespace GameOff.UI.Quiz
|
||||
{
|
||||
public class QuestionUI: MonoBehaviour
|
||||
{
|
||||
public event EventHandler<string> OnChoiceUptade;
|
||||
public static event EventHandler<QuestionChoice> OnAnyQuestionChoice;
|
||||
public static void ClearStaticVariables()
|
||||
{
|
||||
OnAnyQuestionChoice = null;
|
||||
}
|
||||
|
||||
public event EventHandler<string> OnChoiceUpdate;
|
||||
|
||||
[SerializeField] private Text number;
|
||||
[SerializeField] private Image question;
|
||||
@ -25,13 +31,12 @@ namespace GameOff.UI.Quiz
|
||||
{
|
||||
ChoiceUI choice = Instantiate(choicePrefab, choiceHolder);
|
||||
choice.SetUp(answer, this);
|
||||
choice.OnAswerTrigger += ChoiceUI_OnAswerTrigger;
|
||||
choice.OnAnswerTrigger += (sender, e) =>
|
||||
{
|
||||
OnChoiceUpdate?.Invoke(this, e);
|
||||
OnAnyQuestionChoice?.Invoke(this, new QuestionChoice(info.Index, answer));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private void ChoiceUI_OnAswerTrigger(object sender, string e)
|
||||
{
|
||||
OnChoiceUptade?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user