public void StartDialogue(DialogueQuestion dialogue) { this.setRenderers(true); this.sentences.Clear(); this.question.text = dialogue.question; this.answer1.text = dialogue.answers[0]; this.answer2.text = dialogue.answers[1]; this.answer3.text = dialogue.answers[2]; this.answer4.text = dialogue.answers[3]; }
/* * Пошаговая генерация диалога */ void generateDialogue() { if (dialogueSequence[dialogueIteration] == "phrase") // Если сейчас будет фраза { // quizCanvas.gameObject.SetActive(false); Debug.Log(pList.Count); DialoguePhrase crntP = pList[phraseNumber] as DialoguePhrase; if (crntP.speaker == "npc") { npc.GetComponent <DialogueLine>().input = crntP.phrase; Instantiate(npc, parent); if (dialogueSequence[dialogueIteration + 1] != null) { if (dialogueSequence[dialogueIteration + 1] == "phrase") { // generateDialogue(); } } } else if (crntP.speaker == "player") { player.GetComponent <DialogueLine>().input = crntP.phrase; Instantiate(player, parent); } phraseNumber++; Debug.Log('p'); } else if (dialogueSequence[dialogueIteration] == "question") // Если сейчас будет вопрос { Debug.Log(questionNumber); DialogueQuestion crntQ = qList[questionNumber] as DialogueQuestion; qText.text = crntQ.question; Debug.Log(crntQ.question); for (int i = 0; i < crntQ.answers.Length; i++) { answersText[i].text = crntQ.answers[i]; } quizCanvas.gameObject.SetActive(true); questionNumber++; Debug.Log('q'); } dialogueIteration++; }
/* * Метод для получения диалога из ".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); } } }