using System.Collections; using System.Collections.Generic; using UnityEngine; public class QustionData { private QuestionConfig[] questionBasicList; private QuestionConfig[] questionList; private Dictionary datas; public System.Object[] GetAllQuestion() { List t_list = new List(); for (int i = 0; i < questionBasicList.Length; i++) { t_list.Add(questionBasicList[i]); } for (int i = 0; i < questionList.Length; i++) { t_list.Add(questionList[i]); } return t_list.ToArray(); } public List GetList() { List t_list = new List(); for (int i = 0; i< questionBasicList.Length; i++) { t_list.Add(questionBasicList[i]); } for (int i = 0; i < questionList.Length; i++) { t_list.Add(questionList[i]); } return t_list; } public void InitQuestionConfig(QuestionConfig[] questionBasicList) { this.questionBasicList = questionBasicList; this.questionList = new QuestionConfig[0]; datas = new Dictionary(); for (int i = 0; i < questionBasicList.Length; i++) { datas.Add(questionBasicList[i].id, questionBasicList[i]); } } public void InitQuestionConfig(QuestionConfig[] questionBasicList, QuestionConfig[] questionList) { this.questionBasicList = questionBasicList; this.questionList = questionList; datas = new Dictionary(); for (int i = 0; i < questionBasicList.Length; i++) { datas.Add(questionBasicList[i].id, questionBasicList[i]); } for (int i = 0; i < questionList.Length; i++) { datas.Add(questionList[i].id, questionList[i]); } } public QuestionConfig GetConfigById(string id) { if(id != null && datas.ContainsKey(id)) return datas[id]; return null; } //根据 题的ID 获取正确答案对应的索引号 public int GetCorrectIndexById(string id) { if(!datas.ContainsKey(id)) { return -1;//没有这个题 } QuestionConfig config = datas[id]; int res = -1; switch(config.answer) { case "A": res = 0; break; case "B": res = 1; break; case "C": res = 1; break; case "D": res = 1; break; } return res; } } public class QuestionConfig { public string content; public string content_img; public string id; public string desc; public string answer; public string question_type; }