Ejemplo n.º 1
0
    IEnumerator Speaking(string speech, string speaker, bool additive, float textSpeed = 3.5f)
    {
        SpeechPanel.SetActive(true);
        targetSpeech = speech;

        if (!additive)
        {
            SpeechText.text = "";
        }
        else
        {
            targetSpeech = SpeechText.text + speech;
        }
        SpeakerNameText.text = speaker;

        float lettersToWriteInNextFrame = 0;

        while (SpeechText.text != targetSpeech)
        {
            float lettersToWriteInFrame = textSpeed;
            while (lettersToWriteInFrame > 1)
            {
                SpeechText.text += targetSpeech[SpeechText.text.Length];
                lettersToWriteInFrame--;
                if (SpeechText.text == targetSpeech)
                {
                    break;
                }
            }
            lettersToWriteInNextFrame += lettersToWriteInFrame;
            yield return(new WaitForEndOfFrame());
        }
        displayedSpeech = SpeechText.text;
        StopSpeaking();
    }
Ejemplo n.º 2
0
    private void ToNode(int n)
    {
        if (n == 0 && currentNode.id != 0)
        {
            Finish();
            return;
        }

        if (currentSpeechPanel)
        {
            currentSpeechPanel.gameObject.SetActive(false);
        }

        currentNode = story.Nodes[n];
        var charName = currentNode.character;

        if (charName == "...")
        {
            currentSpeechPanel = tutorialSpeechPanel;
        }
        else
        {
            currentSpeechPanel = charName == "player" ? playerSpeechPanel : neutralSpeechPanel;
            if (!characterDict.ContainsKey(charName))
            {
                characterDict.Add(charName, BundleLoader.LoadCharacter(charName));
            }
        }

        currentSpeechPanel.SetNode(currentNode);
        currentSpeechPanel.gameObject.SetActive(true);
    }
    IEnumerator Speaking(string speech, bool additive, string speaker = "")
    {
        SpeechPanel.SetActive(true);                      //make speech panel visible and active
        SpeakerNameText.text = determineSpeaker(speaker); //temporary
        targetSpeech         = speech;

        //check if text is additive or overriding
        if (!additive)
        {
            DialogueText.text = "";
        }
        else
        {
            targetSpeech = DialogueText.text + targetSpeech;
        }

        //reset at the start of new text
        waitingForUserInput = false;

        //while the text in the dialogue box isn't the finished text add text
        while (DialogueText.text != targetSpeech)
        {
            //take the next letter from target speech by counting how many letters have been added to dialogue text already
            DialogueText.text += targetSpeech[DialogueText.text.Length];
            yield return(new WaitForEndOfFrame()); //wait until end of frame
        }

        //once text is finished wait for user to continue
        waitingForUserInput = true;

        while (waitingForUserInput)
        {
            yield return(new WaitForEndOfFrame());
        }
        StopSpeaking();
    }
 ///<summary>
 ///stop all speech and close dialogue panel
 ///</summary>
 public void Close()
 {
     StopSpeaking();
     SpeechPanel.SetActive(false);
 }