Beispiel #1
0
    public void AfficherProchainePhrase()
    {
        if (phrases.Count != 0)
        {
            DetruirePhrasePrecedente();

            DialoguePhrase phrase = phrases.Dequeue();

            dialogueActif = Instantiate(messagePrefab, new Vector3(0, 0, -1000), Quaternion.identity);
            dialogueActif.gameObject.transform.SetParent(messageCanvas.transform, false);

            dialogueActif.displayText = phrase.texte;

            if (phrase.emetteurValue == DialoguePhrase.Emetteur.JOUEUR)
            {
                dialogueActif.target = GameManager._instance.player;
            }
            else if (phrase.emetteurValue == DialoguePhrase.Emetteur.PNJ)
            {
                dialogueActif.target = pnjActuel;
            }
            dialogueActif.timeToDie = 0f;
        }
        else
        {
            GameManager._instance.dialogue = false;
        }
    }
Beispiel #2
0
    private void PlayReplic(DialoguePhrase dialoguePhrase)
    {
        LeftPerson.SetActive(dialoguePhrase.Side == DialoguePhrase.PortraitSide.Left);
        RightPerson.SetActive(dialoguePhrase.Side == DialoguePhrase.PortraitSide.Right);

        switch (dialoguePhrase.Side)
        {
        case DialoguePhrase.PortraitSide.Left:
            LeftPortrait.gameObject.SetActive(dialoguePhrase.Char != null);
            LeftName.gameObject.transform.parent.gameObject.SetActive(dialoguePhrase.Char != null);
            if (dialoguePhrase.Char)
            {
                LeftPortrait.sprite = dialoguePhrase.Char.Portrait;
                LeftName.text       = dialoguePhrase.Char.CharacterName.Text;
            }
            break;

        case DialoguePhrase.PortraitSide.Right:
            RightPortrait.gameObject.SetActive(dialoguePhrase.Char != null);
            RightName.gameObject.transform.parent.gameObject.SetActive(dialoguePhrase.Char != null);
            if (dialoguePhrase.Char)
            {
                RightPortrait.sprite = dialoguePhrase.Char.Portrait;
                RightName.text       = dialoguePhrase.Char.CharacterName.Text;
            }
            break;
        }

        // Typewriter.initialText = dialoguePhrase.Text.Text;
        Typewriter.Write(dialoguePhrase.Text.Text, new string[] { });
        // Typewriter.Write();
    }
        /*
         * Пошаговая генерация диалога
         */
        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);
                }
            }
        }