Esempio n. 1
0
        // Start is called before the first frame update
        void Start()
        {
            XmlElement xRoot = XmlDatabaseConnection.load(file);

            // обход всех узлов в корневом элементе
            foreach (XmlNode xnode in xRoot)
            {
                // получаем атрибут speaker
                if (xnode.Attributes.Count > 0)
                {
                    XmlNode attr = xnode.Attributes.GetNamedItem("speaker");

                    if (attr != null)
                    {
                        if (attr.Value == "npc")
                        {
                            foreach (XmlNode childnode in xnode.ChildNodes)
                            {
                                // если узел - text
                                if (childnode.Name == "text")
                                {
                                    string text = childnode.InnerText;
                                    npc.GetComponent <DialogueLine>().input = text;
                                    Instantiate(npc, parent);
                                }
                            }
                        }
                        else if (attr.Value == "player")
                        {
                            foreach (XmlNode childnode in xnode.ChildNodes)
                            {
                                // если узел - text
                                if (childnode.Name == "text")
                                {
                                    string text = childnode.InnerText;
                                    player.GetComponent <DialogueLine>().input = text;
                                    Instantiate(player, parent);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
    void GetQuestions()
    {
        XmlElement xRoot = XmlDatabaseConnection.load(fileName);

        foreach (XmlNode xnode in xRoot)
        {
            QuizQuestion question = new QuizQuestion();

            if (xnode.Name == "question")
            {
                foreach (XmlNode childnode in xnode.ChildNodes)
                {
                    if (childnode.Name == "text")
                    {
                        question.question = childnode.InnerText;
                    }
                    if (childnode.Name == "answers")
                    {
                        int answerN = 0;

                        foreach (XmlNode answerXnode in childnode.ChildNodes)
                        {
                            if (answerXnode.Name == "answer")
                            {
                                question.answers[answerN] = answerXnode.InnerText;
                                answerN++;
                            }
                        }
                    }
                    // если узел points
                    if (childnode.Name == "points")
                    {
                        question.points = Int32.Parse(childnode.InnerText);
                    }
                }
            }
            else
            {
                Debug.Log(xnode.Name);
            }

            qList.Add(question);
        }
    }
Esempio n. 3
0
        // Start is called before the first frame update
        void Start()
        {
            string     fileName = "Questions";
            XmlElement xRoot    = XmlDatabaseConnection.load(fileName);

            // обход всех узлов в корневом элементе
            foreach (XmlNode xnode in xRoot)
            {
                // получаем атрибут name
                // if(xnode.Attributes.Count>0)
                // {
                //     XmlNode attr = xnode.Attributes.GetNamedItem("name");
                //     if (attr!=null)
                //         Debug.Log(attr.Value);
                // }

                // обходим все дочерние узлы элемента question
                foreach (XmlNode childnode in xnode.ChildNodes)
                {
                    // если узел - text
                    if (childnode.Name == "text")
                    {
                        Debug.Log($"Вопрос: {childnode.InnerText}");
                    }
                    // если узел answer
                    if (childnode.Name == "answer")
                    {
                        Debug.Log($"Ответ: {childnode.InnerText}");
                    }
                    // если узел points
                    if (childnode.Name == "points")
                    {
                        Debug.Log($"Баллов: {childnode.InnerText}");
                    }
                }
            }
        }
        /*
         * Метод для получения диалога из ".xml" файла
         */
        void getDialogue()
        {
            string     fileName = "Questions";
            XmlElement xRoot    = XmlDatabaseConnection.load(fileName);

            foreach (XmlNode xnode in xRoot)
            {
                DialogueQuestion questions = new DialogueQuestion();
                DialoguePhrase   phrases   = new DialoguePhrase();

                if (xnode.Name == "question")
                {
                    dialogueSequence.Add("question");

                    foreach (XmlNode childnode in xnode.ChildNodes)
                    {
                        if (childnode.Name == "text")
                        {
                            questions.question = childnode.InnerText;
                        }
                        if (childnode.Name == "answers")
                        {
                            int answerN = 0;

                            foreach (XmlNode answerXnode in childnode.ChildNodes)
                            {
                                if (answerXnode.Name == "answer")
                                {
                                    questions.answers[answerN] = answerXnode.InnerText;
                                    answerN++;
                                }
                            }
                        }
                        if (childnode.Name == "points")
                        {
                            questions.points = Int32.Parse(childnode.InnerText);
                        }
                    }

                    qList.Add(questions);
                }
                else if (xnode.Name == "phrase")
                {
                    dialogueSequence.Add("phrase");

                    if (xnode.Attributes.Count > 0)
                    {
                        XmlNode attr = xnode.Attributes.GetNamedItem("speaker");

                        if (attr != null)
                        {
                            if (attr.Value == "npc")
                            {
                                phrases.speaker = "npc";

                                foreach (XmlNode childnode in xnode.ChildNodes)
                                {
                                    // если узел - text
                                    if (childnode.Name == "text")
                                    {
                                        phrases.phrase = childnode.InnerText;
                                    }
                                }
                            }
                            else if (attr.Value == "player")
                            {
                                phrases.speaker = "player";

                                foreach (XmlNode childnode in xnode.ChildNodes)
                                {
                                    // если узел - text
                                    if (childnode.Name == "text")
                                    {
                                        phrases.phrase = childnode.InnerText;
                                    }
                                }
                            }
                        }
                    }

                    pList.Add(phrases);
                }
            }
        }