using System.Collections; using System.Collections.Generic; using System; using UnityEngine; public class ExperimentData { public string goalInfo; public ChapterConfig[] chapterConfigs;//章节的配置 public string MRInfo;//MR时刻的文本说明 public string Result;//实验总结 public string MRAssetName;//MR的预制件名字 //public Dictionary question_bank;//核心要点 这里面应该是俩种 一种是 完形填空 一种是选择题 public QustionData mQustionData; //初始化题目 public void InitQuestionBank(LitJson.JsonData data) { mQustionData = new QustionData(); mQustionData.InitQuestionConfig(InitQuestionConfigJsonData(data).ToArray()); } public void InitQuestionBank(LitJson.JsonData data, LitJson.JsonData data2) { mQustionData = new QustionData(); mQustionData.InitQuestionConfig(InitQuestionConfigJsonData(data).ToArray(), InitQuestionConfigJsonData(data2).ToArray()); } //实验目的 public void InitCourseDesc(string str) { goalInfo = str; } //MR游戏说明 public void InitCourseMRDesc(string str) { MRInfo = str; } public void InitCourseResult(string str) { Result = str; } private List InitQuestionConfigJsonData(LitJson.JsonData data) { List dataList = new List(); if (data != null && data.IsArray) { for (int i = 0; i < data.Count; i++) { QuestionConfig cur_data = new QuestionConfig(); LitJson.JsonData s_data = data[i]; cur_data.id = s_data["id"].ToString(); cur_data.desc = s_data["desc"].ToString(); cur_data.content = s_data["content"].ToString(); cur_data.content_img = s_data["content_img"].ToString(); cur_data.answer = s_data["answer"].ToString(); cur_data.question_type = s_data["question_type"].ToString(); dataList.Add(cur_data); } } else { CDebug.Log("格式错误"); } return dataList; } public void InitChapterItemConfig(LitJson.JsonData data) { var list = new List(); if (data.IsArray) { for (int i = 0; i < data.Count; i++) { try { ChapterConfig config_data = new ChapterConfig(); LitJson.JsonData s_data = data[i]; config_data.chapter_name = s_data["chapter_name"].ToString(); config_data.configKey = s_data["id"].ToString(); config_data.sort_id = s_data["sort_id"].ToString(); config_data.course_id = s_data["course_id"].ToString(); string desc = s_data["desc"].ToString(); desc = desc.Replace("[", ""); desc = desc.Replace("]", ""); desc = desc.Replace("'", ""); desc = desc.Replace(" ", ""); string[] secs_ary = desc.Split(','); config_data.btns = new bool[secs_ary.Length]; for (int j = 0; j< secs_ary.Length; j++) { config_data.btns[j] = secs_ary[j].Equals("1"); } list.Add(config_data); } catch(Exception e) { Debug.Log("解析失败" + e); } } } chapterConfigs = list.ToArray(); Array.Sort(chapterConfigs, (a, b)=>int.Parse(a.sort_id).CompareTo(int.Parse(b.sort_id))); } public int GetIndexBySort(string sort) { for(int i = 0; i< chapterConfigs.Length; i++) { if(chapterConfigs[i].sort_id == sort) { return i; } } return 0; } public ChapterConfig GetChapterConfigBySort(int sort) { for (int i = 0; i < chapterConfigs.Length; i++) { if (chapterConfigs[i].sort_id.Equals(sort.ToString())) { return chapterConfigs[i]; } } return null; } public ChapterConfig GetChapterConfigByIndex(int index) { if(chapterConfigs.Length == 0) { return null; } if(index < 0) { index = chapterConfigs.Length - 1; } if(index >=chapterConfigs.Length) { index = 0; } return chapterConfigs[index]; } public bool IsQuestionEmpty { get { return mQustionData == null; } } }