102 lines
3.2 KiB
C#
102 lines
3.2 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class UICheckTest : UIBase
|
||
{
|
||
public Button close;
|
||
QuestionType questionType;
|
||
|
||
List<DataItem2> currentPeoplesQuestion;
|
||
|
||
public Transform content;
|
||
List<QuestionItem> 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<QuestionItem>();
|
||
currentPeoplesQuestion = new List<DataItem2>();
|
||
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<QuestionItem>();
|
||
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("<22><><EFBFBD><EFBFBD>" + item.name + "ѡ<><D1A1><EFBFBD><EFBFBD>" + item.GetTogSelect());
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|