コード例 #1
0
    /* Carica le domande da file */
    private void loadData(bool loadFromStart = true)
    {
        string fileName = MODULE_1;

        if (currentModule == 2)
        {
            fileName = MODULE_2;
        }

        doneQuestions.Clear();
        questionAnswerData.Clear();

        if (!loadFromStart)
        {
            loadDoneQuestions();
        }

        TextAsset dataString = Resources.Load <TextAsset>(fileName);

        string[] rows = dataString.text.Split(new char[] { '\n' });

        for (int k = 0; k < rows.Length; k++)
        {
            if (isStringAcceptable(rows[k]) && !doneQuestions.Contains(k))
            {
                string[] cols = rows[k].Split(new char[] { ';' });

                QuestionAnswer questionAnswer = new QuestionAnswer();
                for (int i = 0; i < cols.Length; i++)
                {
                    if (isStringAcceptable(cols[i]))
                    {
                        if (i == 0)
                        {
                            questionAnswer.setNumberQuestion(Int16.Parse(cols[i]));
                        }
                        else if (i == 1)
                        {
                            questionAnswer.setQuestion(cols[i]);
                        }
                        else
                        {
                            questionAnswer.addAnswer(new Answer(cols[i], i == 2));
                        }
                    }
                }

                questionAnswerData.Insert(new System.Random().Next(0, questionAnswerData.Count), questionAnswer);
            }
        }
    }