using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; public class QuestionProxy : DataProxy { public List m_QuestionInfos; private string m_CurrentTableName; /// /// 根据步骤ID获取 /// /// /// public QuestionInfo GetQuestionInfoByStepId(int stepId) { return m_QuestionInfos.Find(t => t.StepId == stepId.ToString()); } /// /// 设置题目信息 /// public void SetQuestionInfo(QuestionInfo questionInfo) { QuestionInfo tmpQuestionInfo = m_QuestionInfos.Find(t => t.StepId == questionInfo.StepId); if (tmpQuestionInfo == null) { m_QuestionInfos.Add(questionInfo); } else { m_QuestionInfos[m_QuestionInfos.IndexOf(tmpQuestionInfo)] = questionInfo; } m_QuestionInfos.Sort((t1,t2) => t1.StepId.CompareTo(t2.StepId)); WriteStepMsgInfoToTable(); ReadStepMsgInfoFromTable(m_CurrentTableName); } /// /// 从表格读取题库信息 /// /// /// public List ReadStepMsgInfoFromTable(string tableName) { m_CurrentTableName = tableName; string tmpTableName = tableName + GlobalConfig.excelSuffix; List tmpQuestionInfos = new List(); string tmpPath = Path.Combine(GlobalConfig.operateTablePath, tmpTableName); if (!File.Exists(tmpPath)) { ExcelHelper.WriteInfoToExcel(tmpPath, new List()); } m_QuestionInfos = ExcelHelper.ReadInfoFromExcel(tmpPath, 1); return m_QuestionInfos; } public void WriteStepMsgInfoToTable() { string tmpTableName = m_CurrentTableName + GlobalConfig.excelSuffix; string tmpPath = Path.Combine(GlobalConfig.operateTablePath, tmpTableName); ExcelHelper.WriteInfoToExcel(tmpPath, m_QuestionInfos); } } /// /// 从表中读取到的数据信息 /// public class QuestionInfo { /// /// 步骤ID /// public string StepId; /// /// 试题类型 /// public string QuestionType; /// /// 试题题目 /// public string Topic; /// /// 试题选项 /// public string Options; /// /// 试题答案 /// public string Answer; }