QustionData.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class QustionData {
  5. private QuestionConfig[] questionBasicList;
  6. private QuestionConfig[] questionList;
  7. private Dictionary<string, QuestionConfig> datas;
  8. public System.Object[] GetAllQuestion()
  9. {
  10. List<System.Object> t_list = new List<System.Object>();
  11. for (int i = 0; i < questionBasicList.Length; i++)
  12. {
  13. t_list.Add(questionBasicList[i]);
  14. }
  15. for (int i = 0; i < questionList.Length; i++)
  16. {
  17. t_list.Add(questionList[i]);
  18. }
  19. return t_list.ToArray();
  20. }
  21. public List<System.Object> GetList()
  22. {
  23. List<System.Object> t_list = new List<System.Object>();
  24. for (int i = 0; i< questionBasicList.Length; i++)
  25. {
  26. t_list.Add(questionBasicList[i]);
  27. }
  28. for (int i = 0; i < questionList.Length; i++)
  29. {
  30. t_list.Add(questionList[i]);
  31. }
  32. return t_list;
  33. }
  34. public void InitQuestionConfig(QuestionConfig[] questionBasicList)
  35. {
  36. this.questionBasicList = questionBasicList;
  37. this.questionList = new QuestionConfig[0];
  38. datas = new Dictionary<string, QuestionConfig>();
  39. for (int i = 0; i < questionBasicList.Length; i++)
  40. {
  41. datas.Add(questionBasicList[i].id, questionBasicList[i]);
  42. }
  43. }
  44. public void InitQuestionConfig(QuestionConfig[] questionBasicList, QuestionConfig[] questionList)
  45. {
  46. this.questionBasicList = questionBasicList;
  47. this.questionList = questionList;
  48. datas = new Dictionary<string, QuestionConfig>();
  49. for (int i = 0; i < questionBasicList.Length; i++)
  50. {
  51. datas.Add(questionBasicList[i].id, questionBasicList[i]);
  52. }
  53. for (int i = 0; i < questionList.Length; i++)
  54. {
  55. datas.Add(questionList[i].id, questionList[i]);
  56. }
  57. }
  58. public QuestionConfig GetConfigById(string id)
  59. {
  60. if(id != null && datas.ContainsKey(id))
  61. return datas[id];
  62. return null;
  63. }
  64. //根据 题的ID 获取正确答案对应的索引号
  65. public int GetCorrectIndexById(string id)
  66. {
  67. if(!datas.ContainsKey(id))
  68. {
  69. return -1;//没有这个题
  70. }
  71. QuestionConfig config = datas[id];
  72. int res = -1;
  73. switch(config.answer)
  74. {
  75. case "A":
  76. res = 0;
  77. break;
  78. case "B":
  79. res = 1;
  80. break;
  81. case "C":
  82. res = 1;
  83. break;
  84. case "D":
  85. res = 1;
  86. break;
  87. }
  88. return res;
  89. }
  90. }
  91. public class QuestionConfig
  92. {
  93. public string content;
  94. public string content_img;
  95. public string id;
  96. public string desc;
  97. public string answer;
  98. public string question_type;
  99. }