using UnityEngine; using UnityEngine.UI; using QFramework; using System.Collections.Generic; using TMPro; using System; using static OperationController; namespace QFramework.Example { public class UITextQuestionData : UIPanelData { public string title; public List options = new List(); public List answers = new List(); public List btns = new List(); public float waitCloseTime = -1; public bool showAnswer = false; public float rightScore = 0; public float errorScore = 0; public string scoreName = string.Empty; public string format; public string finishedEvent; public string des; public string cellSize; /// /// 0:自动判断 1:单选 2:多选 /// public int OptionType = 0; /// /// 绝对的 不计算分项得分 对就得分 错就不得分 /// public bool absolutely = true; } public partial class UITextQuestion : UIPanel { protected override void OnInit(IUIData uiData = null) { mData = uiData as UITextQuestionData ?? new UITextQuestionData(); // please add init code here TypeEventSystem.Global.Register((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject); } private void OnStepChanged(StepStatusOnChange change) { Hide(); } protected override void OnOpen(IUIData uiData = null) { TypeEventSystem.Global.Register(OnStepChanged).UnRegisterWhenDisabled(gameObject); mData = uiData as UITextQuestionData ?? new UITextQuestionData(); Des.text = string.Empty; Title.text = mData.title; OptionContent.transform.RemoveAllChildren(); if (string.IsNullOrEmpty(mData.cellSize) == false) { OptionContent.GetComponent().cellSize = Utility.GetVector2FromStrArray(mData.cellSize); } for (int i = 0; i < mData.options.Count; i++) { var item = mData.options[i]; GameObject obj = GameObject.Instantiate(OptionPrefab.gameObject, OptionContent.transform); obj.transform.Find("Label").GetComponent().text = item; obj.name = (i + 1).ToString(); bool isGroup = false; switch (mData.OptionType) { case 0: isGroup = mData.answers.Count == 1; break; case 1: isGroup = true; break; case 2: isGroup = false; break; } if (isGroup) { obj.GetComponent().group = OptionContent.GetComponent(); } } BtnContent.RemoveAllChildren(); foreach (var item in mData.btns) { GameObject obj = GameObject.Instantiate(BtnPrefab.gameObject, BtnContent); obj.name = item; var label = obj.transform.Find("Label").GetComponent(); label.text = item; obj.GetComponent