using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class UICheckTest : UIBase { public Button close; QuestionType questionType; List currentPeoplesQuestion; public Transform content; List allQuestionItem; GameObject questionPrefab; private void Awake() { close.onClick.AddListener(() => { UIManager.Instance.DestoryUI(UIType.UICheckTest); }); EventCenter.dispatcher.AddListener(MsgType.OnSubmitQuestion,OnSubmitQuestion); questionPrefab = (GameObject)Resources.Load("UIPrefabs/Question"); RefreshData(); } public void RefreshData() { for (int i = 0; i < content.transform.childCount; i++) { var transform = content.transform.GetChild(i); GameObject.Destroy(transform.gameObject); } var allQuestion = DataManager.Instance.currentPeoplesQuestion; questionType = DataManager.Instance.currentQuesitionType; allQuestionItem = new List(); currentPeoplesQuestion = new List(); switch (questionType) { case QuestionType.CLINICAL_PROBLEM: for (int i = 0; i < allQuestion.Count; i++) { if (allQuestion[i].type == 1) { currentPeoplesQuestion.Add(allQuestion[i]); } } break; case QuestionType.DIAGNOSE_PROBLEM: for (int i = 0; i < allQuestion.Count; i++) { if (allQuestion[i].type == 2) { currentPeoplesQuestion.Add(allQuestion[i]); } } break; case QuestionType.SUGGEST_PROBLEM: for (int i = 0; i < allQuestion.Count; i++) { if (allQuestion[i].type == 3) { currentPeoplesQuestion.Add(allQuestion[i]); } } break; case QuestionType.EXIT_PROBLEM: currentPeoplesQuestion = allQuestion; break; } for (int i = 0; i < currentPeoplesQuestion.Count; i++) { var temp = currentPeoplesQuestion[i]; var newUI = GameObject.Instantiate(questionPrefab, content); QuestionItem currentItem = newUI.GetComponent(); bool isEnd = i == currentPeoplesQuestion.Count - 1; currentItem.Init(temp, isEnd); allQuestionItem.Add(currentItem); } } private void OnSubmitQuestion(Message evt) { for (int i = 0; i < allQuestionItem.Count; i++) { var item = allQuestionItem[i]; if(item.GetTogSelect() == -1) { Debug.Log("Toggle" + item.name + "No answer"); break; } else { DataManager.Instance.currentAnswerQuestion.Add(item.currentData); Debug.Log("ÎÊÌâ" + item.name + "Ñ¡ÔñÁË" + item.GetTogSelect()); } } } }