public void Init() { TextAsset[] datas = Resources.LoadAll <TextAsset>("Config"); for (int i = 0; i < datas.Length; i++) { EAExamPaper p = LoadDataFromAsset(datas[i]); m_papers.Add(p); } }
public EAExamPaper LoadDataFromAsset(TextAsset asset) { EAExamPaper paper = new EAExamPaper(); try { string text = asset.text; string[] ItemInfo = text.Split('\n', '\r'); //start from row 1 for (int i = 1; i < ItemInfo.Length; i++) { if (string.IsNullOrEmpty(ItemInfo[i])) { continue; } string[] ItemData = ItemInfo[i].Split(new char[] { '|' }); EAExamQuestion q = new EAExamQuestion(); q.ParseCSV(ItemData); if (paper.Questions.ContainsKey(q.Question)) { Debug.LogWarning(q.Question); } else { paper.Questions.Add(q.Question, q); } // Debug.LogWarning(q.Question); } } catch (Exception ex) { Debug.LogError(ex.Message); paper = null; } return(paper); }
void OnConfirmButtonClick() { // ClearQuestionNode(); // m_currentResult = m_input.text; m_content.text = string.Empty; List <EAExamPaper> m_papers = EAFileLoaderManager.Instance.Papers; StringBuilder questionBuilder = new StringBuilder(); for (int i = 0; i < m_papers.Count; i++) { EAExamPaper paper = m_papers[i]; foreach (KeyValuePair <string, EAExamQuestion> pair in paper.Questions) { string question = pair.Key; if (pair.Key.Contains(m_input.text)) { questionBuilder.AppendLine(question); PaperType type = GetPaperType(pair.Value.Options); for (int j = 0; j < pair.Value.Options.Count; j++) { string option = pair.Value.Options[j]; if (string.IsNullOrEmpty(option)) { continue; } if (type == PaperType.Judgement) { questionBuilder.AppendLine(option); } else { questionBuilder.AppendLine(IntToLetters(j + 1) + " . " + option); } } // StringBuilder answerBuilder = new StringBuilder(); questionBuilder.AppendLine(); questionBuilder.Append("答案 : "); for (int j = 0; j < pair.Value.Answers.Count; j++) { string answer = pair.Value.Answers[j]; if (string.IsNullOrEmpty(answer)) { continue; } // if (answer == "是" || answer == "否") if (type == PaperType.Judgement) { questionBuilder.Append(IntToJudgement(int.Parse(answer))); } else { questionBuilder.Append(IntToLetters(int.Parse(answer))); } } questionBuilder.AppendLine(""); foreach (string note in pair.Value.Notes) { questionBuilder.AppendLine(note); } questionBuilder.AppendLine(""); questionBuilder.AppendLine(""); questionBuilder.AppendLine(""); questionBuilder.AppendLine(""); questionBuilder.AppendLine(""); AddQuestionNode(questionBuilder.ToString()); // Debug.LogError(questionBuilder.ToString()); } } } m_content.text = questionBuilder.ToString(); }