123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class QustionData {
- private QuestionConfig[] questionBasicList;
- private QuestionConfig[] questionList;
- private Dictionary<string, QuestionConfig> datas;
- public System.Object[] GetAllQuestion()
- {
- List<System.Object> t_list = new List<System.Object>();
- 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<System.Object> GetList()
- {
- List<System.Object> t_list = new List<System.Object>();
- 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<string, QuestionConfig>();
- 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<string, QuestionConfig>();
- 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;
- }
|