Пример #1
0
    private void LoadQuestions(string filename)
    {
        string       file = "Assets/Resources/Quiz/" + filename;
        string       line;
        StreamReader r = new StreamReader(file);

        using (r)
        {
            do
            {
                line = r.ReadLine();
                if (line != null)
                {
                    try {
                        string[] line_values = SplitCsvLine(line);

                        QuestionLine line_entry = new QuestionLine();
                        line_entry.setQuestion(line_values[0]);

                        if (line_values.Length == 3)
                        {
                            List <string> tempAns1 = getShapeResults(line_values[1]);
                            line_entry.setAnswer1(tempAns1.ElementAt(0));
                            tempAns1.RemoveAt(0);
                            line_entry.charactersForAns1 = tempAns1;

                            List <string> tempAns2 = getShapeResults(line_values[2]);
                            line_entry.setAnswer2(tempAns2.ElementAt(0));
                            tempAns2.RemoveAt(0);
                            line_entry.charactersForAns2 = tempAns2;

                            line_entry.setNumAnswers(2);
                        }
                        else if (line_values.Length == 4)
                        {
                            List <string> tempAns1 = getShapeResults(line_values[1]);
                            line_entry.setAnswer1(tempAns1.ElementAt(0));
                            tempAns1.RemoveAt(0);
                            line_entry.charactersForAns1 = tempAns1;

                            List <string> tempAns2 = getShapeResults(line_values[2]);
                            line_entry.setAnswer2(tempAns2.ElementAt(0));
                            tempAns2.RemoveAt(0);
                            line_entry.charactersForAns2 = tempAns2;

                            List <string> tempAns3 = getShapeResults(line_values[3]);
                            line_entry.setAnswer3(tempAns3.ElementAt(0));
                            tempAns3.RemoveAt(0);
                            line_entry.charactersForAns3 = tempAns3;

                            line_entry.setNumAnswers(3);
                        }
                        else if (line_values.Length == 5)
                        {
                            List <string> tempAns1 = getShapeResults(line_values[1]);
                            line_entry.setAnswer1(tempAns1.ElementAt(0));
                            tempAns1.RemoveAt(0);
                            line_entry.charactersForAns1 = tempAns1;

                            List <string> tempAns2 = getShapeResults(line_values[2]);
                            line_entry.setAnswer2(tempAns2.ElementAt(0));
                            tempAns2.RemoveAt(0);
                            line_entry.charactersForAns2 = tempAns2;

                            List <string> tempAns3 = getShapeResults(line_values[3]);
                            line_entry.setAnswer3(tempAns3.ElementAt(0));
                            tempAns3.RemoveAt(0);
                            line_entry.charactersForAns3 = tempAns3;

                            List <string> tempAns4 = getShapeResults(line_values[4]);
                            line_entry.setAnswer4(tempAns4.ElementAt(0));
                            tempAns4.RemoveAt(0);
                            line_entry.charactersForAns4 = tempAns4;

                            line_entry.setNumAnswers(4);
                        }

                        lines.Add(line_entry);
                    } catch (Exception e) {
                        Debug.Log("ERROR in dialogue line number " + (lines.Count));
                    }
                }
            } while (line != null);

            r.Close();
        }
    }