ExperimentData.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System;
  4. using UnityEngine;
  5. public class ExperimentData
  6. {
  7. public string goalInfo;
  8. public ChapterConfig[] chapterConfigs;//章节的配置
  9. public string MRInfo;//MR时刻的文本说明
  10. public string Result;//实验总结
  11. public string MRAssetName;//MR的预制件名字
  12. //public Dictionary<short, QustionData> question_bank;//核心要点 这里面应该是俩种 一种是 完形填空 一种是选择题
  13. public QustionData mQustionData;
  14. //初始化题目
  15. public void InitQuestionBank(LitJson.JsonData data)
  16. {
  17. mQustionData = new QustionData();
  18. mQustionData.InitQuestionConfig(InitQuestionConfigJsonData(data).ToArray());
  19. }
  20. public void InitQuestionBank(LitJson.JsonData data, LitJson.JsonData data2)
  21. {
  22. mQustionData = new QustionData();
  23. mQustionData.InitQuestionConfig(InitQuestionConfigJsonData(data).ToArray(), InitQuestionConfigJsonData(data2).ToArray());
  24. }
  25. //实验目的
  26. public void InitCourseDesc(string str)
  27. {
  28. goalInfo = str;
  29. }
  30. //MR游戏说明
  31. public void InitCourseMRDesc(string str)
  32. {
  33. MRInfo = str;
  34. }
  35. public void InitCourseResult(string str)
  36. {
  37. Result = str;
  38. }
  39. private List<QuestionConfig> InitQuestionConfigJsonData(LitJson.JsonData data)
  40. {
  41. List<QuestionConfig> dataList = new List<QuestionConfig>();
  42. if (data != null && data.IsArray)
  43. {
  44. for (int i = 0; i < data.Count; i++)
  45. {
  46. QuestionConfig cur_data = new QuestionConfig();
  47. LitJson.JsonData s_data = data[i];
  48. cur_data.id = s_data["id"].ToString();
  49. cur_data.desc = s_data["desc"].ToString();
  50. cur_data.content = s_data["content"].ToString();
  51. cur_data.content_img = s_data["content_img"].ToString();
  52. cur_data.answer = s_data["answer"].ToString();
  53. cur_data.question_type = s_data["question_type"].ToString();
  54. dataList.Add(cur_data);
  55. }
  56. }
  57. else
  58. {
  59. CDebug.Log("格式错误");
  60. }
  61. return dataList;
  62. }
  63. public void InitChapterItemConfig(LitJson.JsonData data)
  64. {
  65. var list = new List<ChapterConfig>();
  66. if (data.IsArray)
  67. {
  68. for (int i = 0; i < data.Count; i++)
  69. {
  70. try
  71. {
  72. ChapterConfig config_data = new ChapterConfig();
  73. LitJson.JsonData s_data = data[i];
  74. config_data.chapter_name = s_data["chapter_name"].ToString();
  75. config_data.configKey = s_data["id"].ToString();
  76. config_data.sort_id = s_data["sort_id"].ToString();
  77. config_data.course_id = s_data["course_id"].ToString();
  78. string desc = s_data["desc"].ToString();
  79. desc = desc.Replace("[", "");
  80. desc = desc.Replace("]", "");
  81. desc = desc.Replace("'", "");
  82. desc = desc.Replace(" ", "");
  83. string[] secs_ary = desc.Split(',');
  84. config_data.btns = new bool[secs_ary.Length];
  85. for (int j = 0; j< secs_ary.Length; j++)
  86. {
  87. config_data.btns[j] = secs_ary[j].Equals("1");
  88. }
  89. list.Add(config_data);
  90. }
  91. catch(Exception e)
  92. {
  93. Debug.Log("解析失败" + e);
  94. }
  95. }
  96. }
  97. chapterConfigs = list.ToArray();
  98. Array.Sort(chapterConfigs, (a, b)=>int.Parse(a.sort_id).CompareTo(int.Parse(b.sort_id)));
  99. }
  100. public int GetIndexBySort(string sort)
  101. {
  102. for(int i = 0; i< chapterConfigs.Length; i++)
  103. {
  104. if(chapterConfigs[i].sort_id == sort)
  105. {
  106. return i;
  107. }
  108. }
  109. return 0;
  110. }
  111. public ChapterConfig GetChapterConfigBySort(int sort)
  112. {
  113. for (int i = 0; i < chapterConfigs.Length; i++)
  114. {
  115. if (chapterConfigs[i].sort_id.Equals(sort.ToString()))
  116. {
  117. return chapterConfigs[i];
  118. }
  119. }
  120. return null;
  121. }
  122. public ChapterConfig GetChapterConfigByIndex(int index)
  123. {
  124. if(chapterConfigs.Length == 0)
  125. {
  126. return null;
  127. }
  128. if(index < 0)
  129. {
  130. index = chapterConfigs.Length - 1;
  131. }
  132. if(index >=chapterConfigs.Length)
  133. {
  134. index = 0;
  135. }
  136. return chapterConfigs[index];
  137. }
  138. public bool IsQuestionEmpty
  139. {
  140. get { return mQustionData == null; }
  141. }
  142. }