using System.Collections; using System.Collections.Generic; using UnityEngine; using HJDFrameWork; namespace Level05 { public class AnswerSys : MonoBehaviour { public static AnswerSys Instance = null; [Header("答案集合")] public int[] keys = { 3, 2 }; [Header("当前选择答案")] public int currentKey; [Header("当前题目轮数")] public int QuestionIndex = 1; [Header("答案记录")] public int[] selctedKeys; [Header("问题组")] public Transform questionParent; private GameObject[] questionGroup; [Header("答案组")] public Transform keyParent; private GameObject[] keyGroup; public void Init() { Instance = this; selctedKeys = new int[keys.Length + 1]; GroupCheck(); } void GroupCheck() { questionGroup = new GameObject[questionParent.childCount]; keyGroup = new GameObject[keyParent.childCount]; for (int i = 0; i < questionParent.childCount; i++) { questionGroup[i] = questionParent.GetChild(i).gameObject; } for (int i = 0; i < keyParent.childCount; i++) { keyGroup[i] = keyParent.GetChild(i).gameObject; } GroupActiveUpdate(QuestionIndex, questionGroup); GroupActiveUpdate(QuestionIndex, keyGroup); } void GroupActiveUpdate(int index, GameObject[] group) { for (int i = 0; i < group.Length; i++) { group[i].SetActive(false); } if (group[index - 1] != null) { group[index - 1].SetActive(true); } } public void SetCurrentKey(int key) { currentKey = key; } /// /// 提交答案 /// public void SubmitAnswer() { selctedKeys[QuestionIndex] = currentKey; Debug.Log("记录第" + QuestionIndex + "关答案为" + currentKey); } /// /// 更新新问题的显示 /// public void UpdateQuestion() { ItemManager.Instance.GetItem("emptyAnswerTip").gameObject.SetActive(false); if (currentKey == 0) { //空答案提示 ItemManager.Instance.GetItem("emptyAnswerTip").gameObject.SetActive(true); return; } //执行环节完成处理 ProcessPassAction(QuestionIndex); //本关结束 if (QuestionIndex == questionGroup.Length) { Debug.Log("本关结束"); //完成提示 ItemManager.Instance.GetItem("OverTip").gameObject.SetActive(true); return; } else { //问题索引更新 QuestionIndex += 1; QuestionIndex = Mathf.Clamp(QuestionIndex, 0, questionGroup.Length); Debug.Log(QuestionIndex); //更新环节的标识 ViewManager.Instance.GetViewWnd().UpdateQuestionIndex(QuestionIndex); //显示新的环节 GroupActiveUpdate(QuestionIndex, questionGroup); GroupActiveUpdate(QuestionIndex, keyGroup); //重置当前选择 currentKey = 0; } } public void ProcessPassAction(int passIndex) { switch (passIndex) { case 1: ViewManager.Instance.GetViewWnd().ResetXFDoor(); ItemManager.Instance.GetItem("GuanZi").gameObject.SetActive(true); break; } } } }