mirror of
https://github.com/ConjureETS/GameOff2024.git
synced 2026-03-24 13:10:58 +00:00
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using GameOff.Core;
|
|
using GameOff.Quiz;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace GameOff.UI.Quiz
|
|
{
|
|
public class QuestionUI: MonoBehaviour
|
|
{
|
|
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;
|
|
[SerializeField] private Transform choiceHolder;
|
|
[SerializeField] private ChoiceUI choicePrefab;
|
|
|
|
public void SetUp(QuestionInfo info)
|
|
{
|
|
number.text = $"{info.Index}.";
|
|
question.sprite = info.Question;
|
|
|
|
foreach (string answer in info.Choices)
|
|
{
|
|
ChoiceUI choice = Instantiate(choicePrefab, choiceHolder);
|
|
choice.SetUp(answer, this);
|
|
choice.OnAnswerTrigger += (sender, e) =>
|
|
{
|
|
OnChoiceUpdate?.Invoke(this, e);
|
|
OnAnyQuestionChoice?.Invoke(this, new QuestionChoice(info.Index, answer));
|
|
};
|
|
}
|
|
}
|
|
}
|
|
} |