142 lines
4.6 KiB
C#
142 lines
4.6 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace ZC
|
|
{
|
|
[UIType(UIType.AnswerUI)]
|
|
public class AnswerUI : UIBase
|
|
{
|
|
private Transform Answer;
|
|
private TMP_Text txt_Title;
|
|
private TMP_Text txt_TrueOption;
|
|
private TMP_Text txt_JXContent;
|
|
private TMP_Text txt_Label0;
|
|
private TMP_Text txt_Label1;
|
|
private TMP_Text txt_Label2;
|
|
private TMP_Text txt_Label3;
|
|
private Toggle tog_Option0;
|
|
private Toggle tog_Option1;
|
|
private Toggle tog_Option2;
|
|
private Toggle tog_Option3;
|
|
private Button btn_Last;
|
|
private Button btn_Close;
|
|
private Button btn_Next;
|
|
|
|
//
|
|
private Transform Result;
|
|
private TMP_Text txt_TrueCount;
|
|
private TMP_Text txt_ScoreCount;
|
|
private TMP_Text txt_FalseCount;
|
|
private Button btn_TryAgain;
|
|
private Button btn_Finish;
|
|
|
|
private QuestionBankData _bankData;
|
|
|
|
private int currentIndex = 0;
|
|
|
|
public override void Init()
|
|
{
|
|
base.Init();
|
|
txt_Title = GetValue<TMP_Text>("txt_Title");
|
|
txt_TrueOption = GetValue<TMP_Text>("txt_TrueOption");
|
|
txt_JXContent = GetValue<TMP_Text>("txt_JXContent");
|
|
txt_Label0 = GetValue<TMP_Text>("txt_Label0");
|
|
txt_Label1 = GetValue<TMP_Text>("txt_Label1");
|
|
txt_Label2 = GetValue<TMP_Text>("txt_Label2");
|
|
txt_Label3 = GetValue<TMP_Text>("txt_Label3");
|
|
tog_Option0 = GetValue<Toggle>("tog_Option0");
|
|
tog_Option1 = GetValue<Toggle>("tog_Option1");
|
|
tog_Option2 = GetValue<Toggle>("tog_Option2");
|
|
tog_Option3 = GetValue<Toggle>("tog_Option3");
|
|
btn_Last = GetValue<Button>("btn_Last");
|
|
btn_Close = GetValue<Button>("btn_Close");
|
|
btn_Next = GetValue<Button>("btn_Next");
|
|
|
|
|
|
Answer = GetValue<Transform>("Answer");
|
|
Result = GetValue<Transform>("Result");
|
|
|
|
txt_TrueCount = GetValue<TMP_Text>("txt_TrueCount");
|
|
txt_ScoreCount = GetValue<TMP_Text>("txt_ScoreCount");
|
|
txt_FalseCount = GetValue<TMP_Text>("txt_FalseCount");
|
|
btn_TryAgain = GetValue<Button>("btn_TryAgain");
|
|
btn_Finish = GetValue<Button>("btn_Finish");
|
|
|
|
btn_Last.onClick.AddListener(ClickLastButton);
|
|
btn_Close.onClick.AddListener(ClickCloseButton);
|
|
btn_Next.onClick.AddListener(ClickNextButton);
|
|
|
|
// 读取题库
|
|
_bankData = new QuestionBankData();
|
|
}
|
|
|
|
public override void Dispose()
|
|
{
|
|
base.Dispose();
|
|
btn_Last.onClick.RemoveListener(ClickLastButton);
|
|
btn_Close.onClick.RemoveListener(ClickCloseButton);
|
|
btn_Next.onClick.RemoveListener(ClickNextButton);
|
|
}
|
|
|
|
private void ClickNextButton()
|
|
{
|
|
currentIndex++;
|
|
SetUIContent(_bankData.AnswerDatas[currentIndex]);
|
|
}
|
|
|
|
private void ClickCloseButton()
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
private void ClickLastButton()
|
|
{
|
|
currentIndex--;
|
|
SetUIContent(_bankData.AnswerDatas[currentIndex]);
|
|
}
|
|
|
|
public void SetQuestionBankData(QuestionBankData bankData)
|
|
{
|
|
this._bankData = bankData;
|
|
}
|
|
|
|
private void InitAnswer()
|
|
{
|
|
currentIndex = 0;
|
|
SetUIContent(_bankData.AnswerDatas[currentIndex]);
|
|
}
|
|
|
|
private void SetUIContent(AnswerData data)
|
|
{
|
|
currentIndex = data.index;
|
|
txt_Title.text = data.title;
|
|
txt_Label0.text = data.options[0].content;
|
|
txt_Label1.text = data.options[1].content;
|
|
txt_Label2.text = data.options[2].content;
|
|
txt_Label3.text = data.options[3].content;
|
|
txt_TrueOption.text = data.trueOption;
|
|
txt_JXContent.text = data.analyze;
|
|
|
|
tog_Option0.isOn = false;
|
|
tog_Option1.isOn = false;
|
|
tog_Option2.isOn = false;
|
|
tog_Option3.isOn = false;
|
|
|
|
if (currentIndex >= _bankData.AnswerDatas.Count - 1) // 最后一题
|
|
{
|
|
btn_Next.gameObject.SetActive(false);
|
|
// 提交按钮显示
|
|
}
|
|
else if (currentIndex <= 0) // 第一题
|
|
{
|
|
btn_Last.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
btn_Last.gameObject.SetActive(true);
|
|
btn_Next.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
} |