using System; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; public class QuestionItem : MonoBehaviour { public GameObject topHint; public TextMeshProUGUI hintTxt; public TextMeshProUGUI questionText; public Button submitBtn; public Toggle togPrefab; public ToggleGroup togPrefabGroup; public DataItem2 currentData; int currentSelectIndex = -1; public RectTransform bg; public void Init(DataItem2 data, bool isEnd) { currentData = data; if (currentData != null) { if (!string.IsNullOrEmpty(currentData.introduce)) { topHint.SetActive(true); hintTxt.text = currentData.introduce; } if (isEnd) { submitBtn.gameObject.SetActive(true); submitBtn.onClick.AddListener(OnClickSubmit); } questionText.text = currentData.title; } var replyList = currentData.problemAnswerRespList; for (int i = 0; i < replyList.Count; i++) { Toggle newUI = GameObject.Instantiate(togPrefab, togPrefabGroup.transform); newUI.transform.Find("Label").GetComponent().text = replyList[i].replyText; newUI.gameObject.SetActive(true); newUI.isOn = false; newUI.transform.SetSiblingIndex(i); newUI.onValueChanged.AddListener((bool value) => OnSelect(newUI)); newUI.name = i.ToString(); } } private void OnClickSubmit() { EventCenter.dispatcher.SendMessage(MsgType.OnSubmitQuestion, null); } private void OnSelect(Toggle t) { if (t.isOn) { currentSelectIndex = int.Parse(t.name); } } public int GetTogSelect() { return currentSelectIndex; } }