コード例 #1
0
    // Called when the dialogue is being displayed
    public override IEnumerator RunLine(Yarn.Line line)
    {
        string speaker  = speakerTester.Match(line.text).Value;
        string dialogue = line.text.Remove(0, speaker.Length);

        Speaker.text = speaker;

        string str = "";

        for (int i = 0; i < dialogue.Length; i++)
        {
            if (Input.anyKeyDown)
            {
                Dialogue.text = dialogue;
                yield return(new WaitForSecondsRealtime(0.5f));

                break;
            }
            str          += dialogue[i];
            Dialogue.text = str;

            // Runs the next iteration of this for loop after a certain amount of time
            yield return(new WaitForSecondsRealtime(CrawlTime));
        }

        while (Input.anyKeyDown == false)
        {
            // Runs the next iteration of this while loop on the next frame
            yield return(null);
        }
    }
コード例 #2
0
 /// Runs a line.
 /// <inheritdoc/>
 public override Dialogue.HandlerExecutionType RunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onLineComplete)
 {
     // Start displaying the line; it will call onComplete later
     // which will tell the dialogue to continue
     StartCoroutine(DoRunLine(line, localisationProvider, onLineComplete));
     return(Dialogue.HandlerExecutionType.PauseExecution);
 }
コード例 #3
0
ファイル: DialogueUI.cs プロジェクト: lenitpx/ms_meta_game
    /// Show a line of dialogue, gradually
    public override IEnumerator RunLine(Yarn.Line line)
    {
        //Get the current speaking actor actor by name
        var nextActor = actors[line.text.Substring(0, line.text.IndexOf(':'))];

        line.text = line.text.Substring(line.text.IndexOf(':') + 1);
        line.text.TrimStart(' ');
        if (nextActor == null)
        {
            Debug.LogError("[DialogueUI] Invalid actor name: " + line.text.Substring(0, line.text.IndexOf(':')));
            yield return(null);
        }
        // Switch actors if necessary
        if (nextActor != speakingActor)
        {
            if (speakingActor)
            {
                speakingActor.stopSpeaking();
            }
            speakingActor = nextActor;
        }

        if (textSpeed > 0.0f)
        {
            // Display the line one character at a time
            var stringBuilder = new StringBuilder();

            foreach (char c in line.text)
            {
                stringBuilder.Append(c);
                speakingActor.speak(stringBuilder.ToString());
                yield return(new WaitForSeconds(textSpeed));
            }
        }
        else
        {
            // Display the line immediately if textSpeed == 0
            speakingActor.speak(line.text);
        }

        // Show the 'Continue' prompt when done, if we have one
        if (continuePrompt != null)
        {
            continuePrompt.SetActive(true);
        }

        // Wait for any user input
        while (continueDialogue == false)
        {
            awaitingContinue = true;
            yield return(null);
        }
        continueDialogue = false;
        awaitingContinue = false;

        if (continuePrompt != null)
        {
            continuePrompt.SetActive(false);
        }
    }
コード例 #4
0
    /// Show a line of dialogue, gradually
    private IEnumerator DoRunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onComplete)
    {
        onLineStart?.Invoke();

        userRequestedNextLine = false;

        // The final text we'll be showing for this line.
        string text = localisationProvider.GetLocalisedTextForLine(line);

        if (text == null)
        {
            Debug.LogWarning($"Line {line.ID} doesn't have any localised text.");
            text = line.ID;
        }


        string[] split = text.Split('^');

        bool eventualEnd = end;

        end = false;

        for (int i = 0; i < split.Length; i++)
        {
            if (split[i][0] == '&')
            {
                ds.AddImage(split[i].Remove(0, 1));
            }
            else
            {
                ds.AddToDialogText(currentSpeakerName, split[i], textAlign);
            }


            if (i == split.Length - 1)
            {
                end = eventualEnd;
            }

            // We're now waiting for the player to move on to the next line
            userRequestedNextLine = false;

            // Indicate to the rest of the game that the line has finished being delivered
            onLineFinishDisplaying?.Invoke();

            while (userRequestedNextLine == false)
            {
                yield return(null);
            }
        }

        // Hide the text and prompt
        onLineEnd?.Invoke();

        onComplete();
    }
コード例 #5
0
    /// EDITED FOR SAILING WITH THE GODS
    /// Designed for our dialog system to fill in a dialog object
    private IEnumerator DoRunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onComplete)
    {
        onLineStart?.Invoke();

        userRequestedNextLine = false;

        string text = localisationProvider.GetLocalisedTextForLine(line);

        if (text == null)
        {
            Debug.LogWarning($"Line {line.ID} doesn't have any localised text.");
            text = line.ID;
        }

        //Split one block of text into multiple sections
        string[] split = text.Split('^');

        //If we need to end after the split, we have to save that for later
        //Otherwise, we'll end between the split, which isn't right
        bool eventualEnd = end;

        end = false;

        for (int i = 0; i < split.Length; i++)
        {
            if (split[i][0] == '&')
            {
                ds.AddImage(split[i].Remove(0, 1));
            }
            else
            {
                ds.AddToDialogText(currentSpeakerName, split[i], textAlign);
            }

            //If this is the final part of the split text, remember if this is the end or not
            if (i == split.Length - 1)
            {
                end = eventualEnd;
            }

            // We're now waiting for the player to move on to the next line
            userRequestedNextLine = false;

            // Indicate to the rest of the game that the line has finished being delivered
            onLineFinishDisplaying?.Invoke();

            while (userRequestedNextLine == false)
            {
                yield return(null);
            }
        }

        onLineEnd?.Invoke();

        onComplete();
    }
コード例 #6
0
    /// Show a line of dialogue, gradually
    public override IEnumerator RunLine(Yarn.Line line)
    {
        // Show the text
        lineText.gameObject.SetActive(true);
        boxText.SetActive(true);

        if (textSpeed > 0.0f)
        {
            // Display the line one character at a time
            var stringBuilder = new StringBuilder();
            int count         = 0;
            foreach (char c in line.text)
            {
                count++;
                if (count % voiceSpeed == 0)
                {
                    voice.PlaySound();
                }
                stringBuilder.Append(c);
                yield return(new WaitUntil(() => !instantMessage));

                lineText.text = stringBuilder.ToString();
                yield return(new WaitForSeconds(textSpeed));
            }
        }
        else
        {
            // Display the line immediately if textSpeed == 0
            yield return(new WaitUntil(() => !instantMessage));

            lineText.text = line.text;
        }


        // Wait for any user input
        if (needsInput)
        {
            float timer = 0f;
            while (Input.GetKeyDown(KeyCode.Space) == false &&
                   timer <= autoSkipAfterSeconds)
            {
                timer += Time.deltaTime;
                yield return(null);
            }
        }
        else //otherwise skip ahead
        {
            yield return(new WaitForSeconds(2.0f));
        }


        // Hide the text and prompt
        lineText.gameObject.SetActive(false);
        boxText.SetActive(false);
    }
コード例 #7
0
    public override IEnumerator RunLine(Yarn.Line line)
    {
        //Debug.Log(this.name + ": Running a line!");

        // Add the lines to the text to show. Note that grouping up the
        // lines like this is why I added a paused flag to DialogueRunner
        if (readingDialogue)
        {
            textToShow.Append(line.text.Replace('\n', ' '));
        }

        yield return(null);
    }
コード例 #8
0
    public override System.Collections.IEnumerator RunLine(Yarn.Line line)
    {
        if (lineHandler != null)
        {
            lineHandler(line);
        }

        if (expectedLines.Count > 0)
        {
            Assert.AreEqual(expectedLines.Dequeue(), line.text);
        }

        yield break;
    }
コード例 #9
0
ファイル: DialogueUI.cs プロジェクト: koonce/SoHorrority
    /// Show a line of dialogue, gradually
    public override IEnumerator RunLine(Yarn.Line line)
    {
        TextMeshPro tmp = lineText.GetComponent <TextMeshPro>();

        // Show the text
        lineText.gameObject.SetActive(true);

        if (textSpeed > 0.0f)
        {
            // Display the line one character at a time
            var stringBuilder = new StringBuilder();

            foreach (char c in line.text)
            {
                stringBuilder.Append(c);

                tmp.text = stringBuilder.ToString();
                yield return(new WaitForSeconds(textSpeed));
            }
        }
        else
        {
            // Display the line immediately if textSpeed == 0
            tmp.text = line.text;
        }

        // Show the 'press any key' prompt when done, if we have one
        if (continuePrompt != null)
        {
            continuePrompt.SetActive(true);
        }

        // Wait for any user input
        while (Input.GetKeyDown(KeyCode.Space) == false)
        {
            yield return(null);
        }

        // Hide the text and prompt
        lineText.gameObject.SetActive(false);

        if (continuePrompt != null)
        {
            continuePrompt.SetActive(false);
        }
    }
コード例 #10
0
ファイル: DialogueUI.cs プロジェクト: snackthyme/BulletStory
    /// Show a line of dialogue, gradually
    public override IEnumerator RunLine(Yarn.Line line)
    {
        // Show the text
        lineText.gameObject.SetActive(true);

        if (textSpeed > 0.0f)
        {
            // Display the line one character at a time
            var stringBuilder = new StringBuilder();

            foreach (char c in line.text)
            {
                stringBuilder.Append(c);
                lineText.text = stringBuilder.ToString();
                yield return(new WaitForSeconds(textSpeed));
            }
        }
        else
        {
            // Display the line immediately if textSpeed == 0
            lineText.text = line.text;
        }

        // Show the 'press any key' prompt when done, if we have one
        if (continuePrompt != null)
        {
            continuePrompt.SetActive(true);
        }

        // Wait for any user input
        while (Input.anyKeyDown == false)
        {
            yield return(null);
        }

        // Avoid skipping lines if textSpeed == 0
        yield return(new WaitForEndOfFrame());

        // Hide the text and prompt
        lineText.gameObject.SetActive(false);

        if (continuePrompt != null)
        {
            continuePrompt.SetActive(false);
        }
    }
コード例 #11
0
    // Display the page text
    public override IEnumerator RunLine(Yarn.Line line)
    {
        string s = line.text;

        s = lineIndent + Regex.Replace(s, @"<br>(?=\w)", "<br>" + lineIndent);
        s = s.Replace("END", "<br><align=\"center\"><b>The End</b></align>");
        s = s.Replace("<b><i>", "<font=\"BenguiatStd-BoldItalic SDF\">");
        s = s.Replace("<i><b>", "<font=\"BenguiatStd-BoldItalic SDF\">");
        s = s.Replace("</i></b>", "</font>");
        s = s.Replace("</b></i>", "</font>");

        s = s.Replace("<b>", "<font=\"BenguiatStd-Bold SDF\">");
        s = s.Replace("</b>", "</font>");

        s = s.Replace("<i>", "<font=\"BenguiatStd-BookItalic SDF\">");
        s = s.Replace("</i>", "</font>");

        s = Regex.Replace(s, "<sprite.*?>", new MatchEvaluator(Figure));
        while (s.Substring(s.Length - 4, 4) == "<br>")
        {
            s = s.Substring(0, s.Length - 4);
        }
        description.text = s;


        // dumb fake linking based on line breaks
        s = "";
        string[] stringSeparators = new string[] { "<br>" };
        string[] ss = description.text.Split(stringSeparators, System.StringSplitOptions.RemoveEmptyEntries);

        int t = ss.Length;

        description.ForceMeshUpdate();
        do
        {
            description.text = string.Join("<br>", ss, 0, t);
            description.ForceMeshUpdate();
            t -= 1;
        } while(description.textInfo.lineCount > 25 && t >= 0);
        descriptionContinued.text = string.Join("<br>", ss, t + 1, ss.Length - t - 1);

        yield return(null);
    }
コード例 #12
0
    // Show a line of dialogue, gradually
    public override IEnumerator RunLine(Yarn.Line line)
    {
        //if there are subtitle timings, wait to be told to play
        if (DD.currentNode.SubtitleTimestamps.Count != 0)
        {
            yield return(new WaitUntil(() => MoveToNextLine));

            MoveToNextLine = false;
        }

        // Show the text
        lineText.gameObject.SetActive(true);

        if (textSpeed > 0.0f)
        {
            // Display the line one character at a time
            var stringBuilder = new StringBuilder();

            foreach (char c in line.text)
            {
                stringBuilder.Append(c);
                lineText.text = stringBuilder.ToString();
                yield return(new WaitForSeconds(textSpeed));
            }
        }
        else
        {
            // Display the line immediately if textSpeed == 0
            lineText.text = line.text;
        }

        // Show the 'press any key' prompt when done, if we have one
        if (continuePrompt != null)
        {
            continuePrompt.SetActive(true);
        }

        //if this node has no subtitle timing data then automatically move forward
        if (DD.currentNode.SubtitleTimestamps.Count == 0)
        {
            yield return(new WaitForSeconds(1f));
        }
    }
コード例 #13
0
    public override IEnumerator RunLine(Yarn.Line line)
    {
        lineText.gameObject.SetActive(true);
        var renderedText = "\n" + CheckVars(line.text);

        if (textSpeed > 0.0f)
        {
            var stringBuilder = new StringBuilder();
            stringBuilder.Append(lineText.text);
            foreach (char c in renderedText)
            {
                stringBuilder.Append(c);
                lineText.text = stringBuilder.ToString();
                yield return(new WaitForSeconds(textSpeed));
            }
        }
        else
        {
            lineText.text = lineText.text + renderedText;
        }
    }
コード例 #14
0
ファイル: DialogueUI.cs プロジェクト: Chikanz/Fruit-Head
    /// Show a line of dialogue, gradually
    public override IEnumerator RunLine(Yarn.Line line)
    {
        // Show the text
        lineText.gameObject.SetActive(true);

        if (textSpeed > 0.0f)
        {
            // Display the line one character at a time
            var stringBuilder = new StringBuilder();
            yield return(null);

            //Extract name
            string finalLine = line.text;
            var    splitline = line.text.Split(':');

            Debug.Assert(splitline.Length <= 2, "There's two colons in the node " + line.text);

            if (splitline.Length > 1)
            {
                var name = UppercaseFirst(splitline[0]);

                //Fire off event
                if (TalkingTo != name && OnTargetChanged != null)
                {
                    TalkingTo = name;
                    OnTargetChanged(TalkingTo);
                }

                charName.text = name;
                finalLine     = splitline[1].Substring(1); //Remove space on dialogue

                if (finalLine.Length >= 142)
                {
                    Debug.Log("Line might be off screen! Line:" + finalLine);
                }
            }

            foreach (char c in finalLine)
            {
                stringBuilder.Append(c);
                lineText.text = stringBuilder.ToString();

                //Early exit
                if (InputManager.GetButtonDown("UI_Submit"))
                {
                    lineText.text = finalLine;
                    break;
                }
                else
                {
                    yield return(new WaitForSeconds(textSpeed));
                }
            }
        }
        else
        {
            // Display the line immediately if textSpeed == 0
            lineText.text = line.text;
        }

        yield return(null); //(HACKY HACK HACK) Skip a frame to stop early exit triggering continue

        // Show the 'press any key' prompt when done, if we have one
        if (continuePrompt != null)
        {
            continuePrompt.SetActive(true);
        }

        // Wait for any user input
        while (InputManager.GetButtonDown("UI_Submit") == false)
        {
            yield return(null);
        }

        // Hide the text and prompt
        lineText.gameObject.SetActive(false);

        if (continuePrompt != null)
        {
            continuePrompt.SetActive(false);
        }
    }
コード例 #15
0
 public void SetUp()
 {
     line = new Yarn.Line();
 }
コード例 #16
0
    /// Show a line of dialogue, gradually
    public override IEnumerator RunLine(Yarn.Line line)
    {
        string[] splitbycolon = line.text.Split(":".ToCharArray(), 2);
        string   speaker      = splitbycolon[0];
        string   content      = splitbycolon[1];

        // Debug.Log(speaker + ", " + content);
        // Show the text
        if (speaker.Equals("Noa"))
        {
            lineTextNoa.transform.parent.gameObject.SetActive(true);
        }
        else
        {
            lineTextYun.transform.parent.gameObject.SetActive(true);
        }



        if (textSpeed > 0.0f)
        {
            // Display the line one character at a time
            var stringBuilder = new StringBuilder();

            foreach (char c in content)
            {
                stringBuilder.Append(c);
                if (speaker.Equals("Noa"))
                {
                    lineTextNoa.text = stringBuilder.ToString();
                }
                else
                {
                    lineTextYun.text = stringBuilder.ToString();
                }
                yield return(new WaitForSeconds(textSpeed));
            }
        }
        else
        {
            // Display the line immediately if textSpeed == 0
            if (speaker.Equals("Noa"))
            {
                lineTextNoa.text = content;
            }
            else
            {
                lineTextYun.text = content;
            }
        }

        // Show the 'press any key' prompt when done, if we have one
        if (continuePrompt != null)
        {
            continuePrompt.SetActive(true);
        }

        // Wait for any user input
        //while (Input.anyKeyDown == false)
        while (Input.GetKeyDown(KeyCode.Space) == false)
        {
            yield return(null);
        }

        // Hide the text and prompt
        lineTextYun.transform.parent.gameObject.SetActive(false);
        lineTextNoa.transform.parent.gameObject.SetActive(false);

        if (continuePrompt != null)
        {
            continuePrompt.SetActive(false);
        }
    }
コード例 #17
0
    public override IEnumerator RunLine(Yarn.Line line)
    {
        dialogueUIFrame.SetActive(true);
        displayedText.text = line.text;

        string[] nameLine = line.text.Split(':');
        if (nameLine.Length != 2)
        {
            Debug.Log("Not properly formatted line (split)");
        }

        string name = nameLine[0];

        currentCharacter.sprite = charDict[name].portrait;

        currentFullLine    = nameLine[1].TrimStart(' ');
        displayedText.text = currentFullLine;

        // These next few lines of bullshit let the player click through
        // the same line
        lineFullyShown     = false;
        newSegment         = true;
        charsCounted       = false;
        numCharsShownSoFar = 0;
        while (!lineFullyShown)
        {
            if (newSegment)
            {
                // when we show a new segment, we need to wait a frame to be
                // able to count the characters displaued
                newSegment = false;
                yield return(null);
            }
            else if (!charsCounted)
            {
                int numCharsVisibleNow = displayedText.cachedTextGenerator.characterCountVisible;
                numCharsShownSoFar += numCharsVisibleNow;
                charsCounted        = true;
                if (numCharsShownSoFar == currentFullLine.Length)
                {
                    lineFullyShown = true;
                }
                else     // still haven't shown the full line
                // wait for player input to show the next line
                {
                    while (!Input.GetButtonDown("interact"))
                    {
                        yield return(null);
                    }
                    charsCounted       = false;
                    newSegment         = true;
                    displayedText.text = currentFullLine.Substring(numCharsShownSoFar);
                }
            }
        }



        // wait for user input to display next line
        while (!Input.GetButtonDown("interact"))
        {
            yield return(null);
        }
        yield return(null);
    }
コード例 #18
0
ファイル: DialogueUI.cs プロジェクト: pmaxwellward/SLOT
    /// Show a line of dialogue, gradually
    public override IEnumerator RunLine(Yarn.Line line)
    {
        // Holds GameObject of currently speaking character
        GameObject speaker;

        //Set clickToSkip button to active
        clickToSkip.gameObject.SetActive(true);

        var speakerStringBuilder = new StringBuilder();

        //Check to see who is speaking
        foreach (char c in line.text)
        {
            if (c != ':')
            {
                speakerStringBuilder.Append(c);
                speakerName = speakerStringBuilder.ToString();
            }
            else
            {
                break;
            }
        }

        //Find the name found from the Yarn Line
        if (speakerName == "CW")
        {
            speaker = GameObject.Find("CW");
        }
        else if (speakerName == "Narrator")
        {
            speaker            = GameObject.Find("Narrator");
            lineText.fontStyle = FontStyle.Italic;
        }
        else
        {
            speaker = GameObject.Find("NPC");
        }


        //If found, put dialogue container at the speakers position
        if (speaker != null)
        {
            dialogueContainer.transform.position = speaker.transform.position;
        }
        else
        {
            Debug.Log("speaker does not have a dialogue container!");
        }


        //Show the NPC portrait
        NPC_Portrait.SetActive(true);


        //Removes Character name, colon, and space from the displayed dialogue
        line.text = line.text.Remove(0, speakerName.Length + 2);


        // Show the text
        if (textSpeed > 0.0f)
        {
            lineText.gameObject.SetActive(true);

            // Display the line one character at a time
            var stringBuilder = new StringBuilder();
            foreach (char c in line.text)
            {
                stringBuilder.Append(c);
                lineText.text = stringBuilder.ToString();
                yield return(new WaitForSeconds(textSpeed));

                //if skipContinue button is pushed, display line immediately
                if (skipContinue == true)
                {
                    skipContinue  = false;
                    lineText.text = line.text;
                    break;
                }
            }
        }
        else
        {
            // Display the line immediately if textSpeed == 0
            lineText.text = line.text;
        }

        //Turn off clickToSkip button
        clickToSkip.gameObject.SetActive(false);

        // Show the 'press any key' prompt when done, if we have one
        if (continuePrompt != null)
        {
            continuePrompt.SetActive(true);
        }


        while (Input.anyKeyDown == false)
        {
            yield return(null);
        }

        if (continuePrompt != null)
        {
            continuePrompt.SetActive(false);
        }

        // Clear the speaker name
        speakerName = string.Empty;
        //"Unpush" skipToClick button
        skipContinue = false;
        //If text is italic, back to normal
        if (lineText.fontStyle == FontStyle.Italic)
        {
            lineText.fontStyle = FontStyle.Normal;
        }
    }
コード例 #19
0
    private IEnumerator DoRunLine(Yarn.Line line, ILineLocalisationProvider localisationProvider, System.Action onComplete)
    {
        Debug.Log("Beta");
        dialogueContainer.SetActive(true);
        ds = DialogState.Rolling;
        string text = localisationProvider.GetLocalisedTextForLine(line);

        // Yarn Spinner doesnt let you escape certain characters so we need to do workarounds like this :/
        text = Regex.Replace(text, "&", "#");

        textDisplay.text = "";
        int i                  = -1;
        int tagStartIndex      = -1;
        int styleTagStartIndex = -1;
        var match              = Regex.Match(text, "([A-z ]+): ");

        // Disable previous speaker's portrait.
        if (speaker != null)
        {
            speaker.portraitUI.SetActive(false);
        }

        // Get portrait with the captured group
        if (characterDatas.TryGetValue(match.Groups[1].Value, out speaker))
        {
            speaker.portraitUI.SetActive(true);
        }
        else
        {
            Debug.LogWarning("Couldnt find portrait for character named " + match.Groups[1].Value);
        }

        // Chop off the front of text
        text = text.Substring(match.Length);

        if (match.Groups[1].Value == "Notebook")
        {
            Notebook.instance.TakeNote(text);
        }
        typingSpeed = DEFAULT_TYPING_SPEED;
        foreach (char letter in text)
        {
            i++;
            if (letter == '<')
            {
                styleTagStartIndex = i;
            }
            if (letter == '>')
            {
                styleTagStartIndex = -1;
            }
            if (letter == '~')             // We're looking at
            {
                tagStartIndex = i;
            }
            if (tagStartIndex != -1)
            {
                if (letter == '`')
                {
                    tagHelper(text.Substring(tagStartIndex + 1, i - tagStartIndex - 1));
                    tagStartIndex = -1;
                }
                continue;
            }
            textDisplay.text += letter;
            if ("aeiouyAEIOUY".IndexOf(letter) == -1)
            {
                //play a voice synthesis sound
            }
            if (!skipRolling)
            {
                if (letter != ' ' && styleTagStartIndex == -1)
                {
                    yield return(new WaitForSeconds(typingSpeed));
                }
            }
        }
        skipRolling = false;
        ds          = DialogState.Rolled;

        // Show the continue prompt, if we have one
        // TODO: continue prompt

        Debug.Log(Time.time - timeSinceSkipRolling);
        // Wait while they arent clicking or they are locked out
        while (!Input.GetMouseButtonDown(0) || MouseNearNotebook() || (Notebook.instance.leaveNotebookFrame == Time.frameCount) || (Time.time - timeSinceSkipRolling < TEXT_ADVANCE_LOCKOUT))
        {
            yield return(null);
        }

        yield return(new WaitForEndOfFrame());

        speaker.portraitUI.SetActive(false);
        // Remove the continue prompt if we have one


        onComplete();
    }
コード例 #20
0
    /// Show a line of dialogue, gradually
    public override IEnumerator RunLine(Yarn.Line line)
    {
        float  timeSpent = 0f;
        string reline    = line.text;
        string result    = "";

        if (line.text.Contains("me: "))
        {
            timeSpent = 0.1f;
            result    = reline.Replace("me: ", "<b>me:</b> ");
        }
        else if (line.text.Contains("ivory: "))
        {
            timeSpent = line.text.Length * Random.Range(0.05f, 0.2f);
            result    = reline.Replace("ivory: ", "<b>ivory: </b>");
        }
        yield return(new WaitForSeconds(timeSpent));

        // Show the text
        //  lineText.gameObject.SetActive(true);

        /*if (textSpeed > 0.0f)
         * {
         *  // Display the line one character at a time
         *  var stringBuilder = new StringBuilder();
         *
         *  foreach (char c in line.text)
         *  {
         *      stringBuilder.Append(c);
         *     // lineText.text = stringBuilder.ToString();
         *      yield return new WaitForSeconds(textSpeed);
         *  }
         * }
         * else
         * {
         *  // Display the line immediately if textSpeed == 0
         * //  lineText.text = line.text;
         * }*/
        GameObject chatline = Instantiate(Services.Prefabs.ChatLine,
                                          Services.Prefabs.ChatLine.transform.position,
                                          Services.Prefabs.ChatLine.transform.rotation);

        //chatline.GetComponent<RectTransform>().pivot = new Vector2(0, 1);
        chatline.transform.SetParent(Services.Main.ScrollingObj.transform, false);


        chatline.GetComponent <Text>().text = result;
        if (line.text.Contains("ivory: "))
        {
            Services.EventManager.Fire(new NewChatLineAdded());
        }
        Canvas.ForceUpdateCanvases();
        Services.Main.ScrollingObj.transform.parent.GetComponent <ScrollRect>().verticalNormalizedPosition = 0f;

        Canvas.ForceUpdateCanvases();
        // Show the 'press any key' prompt when done, if we have one
        if (continuePrompt != null)
        {
            continuePrompt.SetActive(true);
        }

        // Wait for any user input

        /* while (Input.anyKeyDown == false)
         * {
         *   yield return null;
         * }*/

        // Hide the text and prompt
        // lineText.gameObject.SetActive(false);

        if (continuePrompt != null)
        {
            continuePrompt.SetActive(false);
        }
    }
コード例 #21
0
ファイル: DialogueUI.cs プロジェクト: rcalderking/SLOT
    /// Show a line of dialogue, gradually
    public override IEnumerator RunLine(Yarn.Line line)
    {
        GameObject speaker; // Holds GameObject of currently speaking character
        var        speakerStringBuilder = new StringBuilder();

        //Check to see who is speaking
        foreach (char c in line.text)
        {
            if (c != ':')
            {
                speakerStringBuilder.Append(c);
                speakerName = speakerStringBuilder.ToString();
            }
            else
            {
                break;
            }
        }

        speaker = GameObject.Find(speakerName); //Find the name found from the Yarn Line
        //GameObject speakerPortrait = GameObject.Find(speakerName + "_portrait");

        if (speaker != null) //If found, put dialogue container at the speakers position
        {
            dialogueContainer.transform.position = speaker.transform.position;
        }

        foreach (var image in portraits)
        {
            if (image.name == speakerName + "_portrait")
            {
                image.gameObject.SetActive(true);
            }
        }

        line.text = line.text.Remove(0, speakerName.Length + 2); //Removes Character name, colon, and space from the displayed dialogue
        // Show the text
        lineText.gameObject.SetActive(true);

        if (textSpeed > 0.0f)
        {
            // Display the line one character at a time
            var stringBuilder = new StringBuilder();
            foreach (char c in line.text)
            {
                stringBuilder.Append(c);
                lineText.text = stringBuilder.ToString();
                yield return(new WaitForSeconds(textSpeed));
            }
        }
        else
        {
            // Display the line immediately if textSpeed == 0
            lineText.text = line.text;
        }

        // Show the 'press any key' prompt when done, if we have one
        if (continuePrompt != null)
        {
            continuePrompt.SetActive(true);
        }

        // Wait for any user input
        while (Input.anyKeyDown == false)
        {
            yield return(null);
        }


        // Hide the text,prompt, and portrait
        //lineText.gameObject.SetActive(false);


        if (continuePrompt != null)
        {
            continuePrompt.SetActive(false);
        }

        speakerName = string.Empty; // Clear the speaker name
    }
コード例 #22
0
    /// Show a line of dialogue, gradually
    public override IEnumerator RunLine(Yarn.Line line)
    {
        // Show the text
        lineText.gameObject.SetActive(true);

        if (textSpeed > 0.0f)
        {
            // print("At the top of the if");
            // Display the line one character at a time
            var stringBuilder = new StringBuilder();

            // Start coroutine that checks for input while the text is printing
            bool      shouldInterrupt  = false;
            Coroutine waitForInterrupt = StartCoroutine(WaitForInput((isDone) =>
            {
                shouldInterrupt = isDone;
                return;
            }));

            foreach (char c in line.text)
            {
                // If we should interrupt then display entire text and break out of loop
                if (shouldInterrupt)
                {
                    lineText.text = line.text;
                    break;
                }
                stringBuilder.Append(c);
                lineText.text = stringBuilder.ToString();
                yield return(new WaitForSeconds(textSpeed));
            }

            // Make sure to stop the coroutine if it's still running
            if (waitForInterrupt != null)
            {
                StopCoroutine(waitForInterrupt);
                waitForInterrupt = null;
            }
        }
        else
        {
            // Display the line immediately if textSpeed == 0
            lineText.text = line.text;
        }

        // Show the 'press any key' prompt when done, if we have one
        if (continuePrompt != null)
        {
            continuePrompt.SetActive(true);
        }

        // Wait for user input
        // Wait a little bit so that input is not detected at the same time as the interrupt
        yield return(new WaitForSeconds(0.02f));

        while (rewiredPlayer.GetButtonDown("UISubmit") == false)
        {
            yield return(null);
        }

        // Hide the text and prompt
        lineText.gameObject.SetActive(false);

        if (continuePrompt != null)
        {
            continuePrompt.SetActive(false);
        }
    }
コード例 #23
0
ファイル: DialogueSystem.cs プロジェクト: justinaray828/CWMA
    public override IEnumerator RunLine(Yarn.Line line)
    {
        while (cameraTransition.startZoom)
        {
            dialoguePanelController.EnableDialogue(false);
            yield return(null);//Wait until the camera is all the way zoomed in to continue
        }

        List <KeyValuePair <int, string> > commands = new List <KeyValuePair <int, string> >();
        string lineString = line.text;

        lineString = ParseLine(lineString, ref commands);

        /*foreach (KeyValuePair<int, string> command in commands)
         * {
         *  Debug.Log(command.Key + " -> " + command.Value);
         * }*/

        // Show the text
        dialoguePanelController.PopUp = true;
        dialoguePanelController.EnableDialogue(true);

        if (textSpeed > 0.0f)
        {
            // Display the line one character at a time
            var stringBuilder = new StringBuilder();
            int counter       = 0;

            audioM.PlayBlip(dialoguePanelController.GetCurrentCharacter().talkingPitch);

            foreach (char c in lineString)
            {
                //InputPressed is set to true via the Update method (which is run before coroutines each frame)
                if (inputPressed)
                {
                    dialoguePanelController.dialogueText.text = lineString;
                    inputPressed = false;
                    counter      = 0;
                    break;
                }
                // for each index of the string, check if a markup is set for that index
                // (This could definitely be written to be more efficient. I just jotted this down for nwo)
                foreach (KeyValuePair <int, string> command in commands)
                {
                    if (command.Key == counter)
                    {
                        ExecuteMarkUp(command.Value);
                    }
                }

                //if pause markup has been executed, textPaused will be set to true
                if (textPaused)
                {
                    //loop for amount of time equal to the pause time set
                    for (float timer = textPauseTime; timer >= 0; timer -= Time.deltaTime)
                    {
                        //check for input as we go
                        if (inputPressed)
                        {
                            break;
                        }
                        yield return(null);
                    }

                    textPaused = false;
                    if (inputPressed)
                    {
                        dialoguePanelController.dialogueText.text = lineString;
                        inputPressed = false;
                        counter      = 0;
                        break;
                    }
                }

                counter++;
                stringBuilder.Append(c);
                dialoguePanelController.dialogueText.text = stringBuilder.ToString();
                yield return(new WaitForSeconds(textSpeed));
            }
            audioM.StopBlip();
        }
        else
        {
            // Display the line immediately if textSpeed == 0
            dialoguePanelController.dialogueText.text = lineString;
        }

        ///Stops all talking in scene after text is done
        talkingStop.StopAllTalking();

        // Show the 'press any key' prompt when done, if we have one
        if (continuePrompt != null)
        {
            continuePrompt.SetActive(true);
        }

        // Wait for any user input
        while (inputPressed == false)
        {
            yield return(null);
        }

        //reset Markup variables
        ResetFields();

        inputPressed = false;
        if (continuePrompt != null)
        {
            continuePrompt.SetActive(false);
        }
    }
コード例 #24
0
ファイル: TMPDialogueUI.cs プロジェクト: brimism/LatinVR
    /// Show a line of dialogue, gradually
    public override IEnumerator RunLine(Yarn.Line line)
    {
        lineText.gameObject.SetActive(false);
        lineText.gameObject.SetActive(true);
        // Reset text
        customTagHandler.StopAllCoroutines();
        customTagHandler.clearClones();
        prevColors.Clear();
        lineText.SetText(customTagHandler.ParseForCustomTags(YarnRTFToTMP(line.text)));
        lineText.ForceMeshUpdate();
        customTagHandler.ApplyTagEffects();

        // Set up teletype by setting alpha to 0
        TMPro.TMP_Text     m_TextComponent = lineText.GetComponent <TMPro.TMP_Text>();
        TMPro.TMP_TextInfo textInfo        = m_TextComponent.textInfo;
        while (textInfo.characterCount == 0)
        {
            yield return(new WaitForSeconds(0.25f));
        }
        Color32[] newVertexColors;
        for (int currentCharacter = 0; currentCharacter < textInfo.characterCount; currentCharacter++)
        {
            int materialIndex = textInfo.characterInfo[currentCharacter].materialReferenceIndex;
            newVertexColors = textInfo.meshInfo[materialIndex].colors32;
            int vertexIndex = textInfo.characterInfo[currentCharacter].vertexIndex;
            // Save prev color
            if (textInfo.characterInfo[currentCharacter].isVisible)
            {
                for (int j = 0; j < 4; j++)
                {
                    prevColors.Add(textInfo.meshInfo[materialIndex].colors32[vertexIndex + j]);
                }
            }
            else
            {
                for (int j = 0; j < 4; j++)
                {
                    prevColors.Add(new Color32(0, 0, 0, 0));
                }
            }
            // Set color to transparent
            if (textInfo.characterInfo[currentCharacter].isVisible)
            {
                for (int j = 0; j < 4; j++)
                {
                    newVertexColors[vertexIndex + j] = new Color32(textInfo.meshInfo[materialIndex].colors32[vertexIndex + j].r, textInfo.meshInfo[materialIndex].colors32[vertexIndex + j].g, textInfo.meshInfo[materialIndex].colors32[vertexIndex + j].b, 0);
                }
                m_TextComponent.UpdateVertexData(TMPro.TMP_VertexDataUpdateFlags.Colors32);
            }
        }

        if (textSpeed > 0.0f)
        {
            // Display the line one character at a time
            for (int i = 0; i < textInfo.characterCount; i++)
            {
                int materialIndex = textInfo.characterInfo[i].materialReferenceIndex;
                newVertexColors = textInfo.meshInfo[materialIndex].colors32;
                int vertexIndex = textInfo.characterInfo[i].vertexIndex;
                if (textInfo.characterInfo[i].isVisible)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        newVertexColors[vertexIndex + j] = prevColors[4 * i + j];
                    }
                    m_TextComponent.UpdateVertexData(TMPro.TMP_VertexDataUpdateFlags.Colors32);
                }
                yield return(new WaitForSeconds(textSpeed));
            }
        }
        else
        {
            // Display the entire line immediately if textSpeed <= 0
            for (int currentCharacter = 0; currentCharacter < textInfo.characterCount; currentCharacter++)
            {
                int materialIndex = textInfo.characterInfo[currentCharacter].materialReferenceIndex;
                newVertexColors = textInfo.meshInfo[materialIndex].colors32;
                int vertexIndex = textInfo.characterInfo[currentCharacter].vertexIndex;
                // Set color back to the color it is supposed to be
                if (textInfo.characterInfo[currentCharacter].isVisible)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        newVertexColors[vertexIndex + j] = prevColors[4 * currentCharacter + j];
                    }
                    m_TextComponent.UpdateVertexData(TMPro.TMP_VertexDataUpdateFlags.Colors32);
                }
            }
        }

        // Reset custom tag runner
        customTagHandler.ClearParsedTags();

        // Show the 'press any key' prompt when done, if we have one
        if (continuePrompt != null)
        {
            continuePrompt.SetActive(true);
        }

        // Wait for trigger press
        while (gameManager.LH_Trigger == false && gameManager.RH_Trigger == false)
        {
            yield return(null);
        }

        // Avoid skipping lines if textSpeed == 0
        yield return(new WaitForEndOfFrame());

        // Hide the text and prompt
        lineText.gameObject.SetActive(false);

        if (continuePrompt != null)
        {
            continuePrompt.SetActive(false);
        }
    }
コード例 #25
0
    // Show a line of dialogue, gradually
    public override IEnumerator RunLine(Yarn.Line line)
    {
        //We'll always start a line assuming it can't be skipped.
        blockSkip = false;
        // Show the text
        lineText.gameObject.SetActive(true);

        StringBuilder displayText = new StringBuilder();

        string rawText = line.text;

        string[] parsedTextChunks = inlineStyleRegex.Split(rawText);

        MatchCollection collection = inlineStyleRegex.Matches(rawText);

        string[] inlineCommandStrings = new string[collection.Count];
        Dictionary <int, List <string> > inlineCommandAndIndexPairs = new Dictionary <int, List <string> >();
        int index = 0;

        foreach (Match match in collection)
        {
            string trimmedString = match.Value.Trim(new char[] { '{', '}' });
            //We have an isolated command
            Debug.Log("Match val: " + match.Value);
            Debug.Log("Trimmed string: " + trimmedString);
            inlineCommandStrings[index] = trimmedString;
            ++index;
        }

        for (int i = 0; i < inlineCommandStrings.Length; ++i)
        {
            Debug.Log("Command String Bank " + i + ":" + inlineCommandStrings[i]);
        }

        Debug.Log("Split line into " + parsedTextChunks.Length + " chunks");
        for (int i = 0; i < parsedTextChunks.Length; ++i)
        {
            bool commandFound = false;
            for (int j = 0; j < inlineCommandStrings.Length; ++j)
            {
                //Debug.Log("Comparing chunk: " + parsedTextChunks[i] + " against command: " + inlineCommandStrings[j]);
                if (inlineCommandStrings[j] == parsedTextChunks[i])
                {
                    Debug.Log("Command found: " + inlineCommandStrings[j] + " at index: " + displayText.Length);
                    if (!inlineCommandAndIndexPairs.ContainsKey(displayText.Length))
                    {
                        inlineCommandAndIndexPairs[displayText.Length] = new List <string>();
                    }
                    inlineCommandAndIndexPairs[displayText.Length].Add(inlineCommandStrings[j]);
                    commandFound = true;
                    continue;
                }
            }
            //Guess it wasn't a command match
            if (!commandFound)
            {
                displayText.Append(parsedTextChunks[i]);
                Debug.Log("Text Chunk: " + parsedTextChunks[i]);
            }
        }

        //Now that we have commands extracted and their cursor positions tagged, we can go about building a catolog of inline style tags
        Dictionary <int, OpenStyleTag> openStyleTags = new Dictionary <int, OpenStyleTag>();
        MatchCollection tagOpenCollection            = tagOpenRegex.Matches(displayText.ToString());

        foreach (Match match in tagOpenCollection)
        {
            //Ok, I need to generate a closed tag that can match the open tag.
            string generatedClosedTag = match.Value;
            //Strip out any parameters.
            generatedClosedTag = Regex.Replace(generatedClosedTag, @"\s[^>]*", "");
            generatedClosedTag = Regex.Replace(generatedClosedTag, "=[^>]*", "");
            //Add a /, and you're left with a generated closing tag.
            generatedClosedTag = generatedClosedTag.Insert(1, "/");

            openStyleTags[match.Index] = new OpenStyleTag(match.Value, generatedClosedTag);
            Debug.Log("Tag Open Match: " + match.Value);
            Debug.Log("Generated closed: " + generatedClosedTag);
        }

        Dictionary <int, string> closedStyleTags    = new Dictionary <int, string>();
        MatchCollection          tagCloseCollection = tagCloseRegex.Matches(displayText.ToString());

        foreach (Match match in tagCloseCollection)
        {
            closedStyleTags[match.Index] = match.Value;
            Debug.Log("Tag Closed Match: " + match.Value);
        }

        //Now we know when a tag will begin, will it will end, and the tag itself.
        //This will let us assemble our string correctly while we're parsing it char by char.
        //Of course, we can just

        Debug.Log("---Parsing complete, starting text render---");
        if (textSpeed > 0.0f)
        {
            // Display the line one character at a time
            var stringBuilder = new StringBuilder();
            int currCharIndex = 0;

            var enumerator     = displayText.ToString().GetEnumerator();
            int commandIndex   = 0;
            int closeTagLength = 0;
            while (enumerator.MoveNext())
            {
                char c = enumerator.Current;

                //We've run across a point where a command should execute.
                if (inlineCommandAndIndexPairs.ContainsKey(currCharIndex))
                {
                    for (int i = 0; i < inlineCommandAndIndexPairs[currCharIndex].Count; ++i)
                    {
                        yield return(parseInlineCommand(inlineCommandAndIndexPairs[currCharIndex][i], false));
                    }
                    ++commandIndex;
                }

                if ((im.GetButtonDown(FSTokens.InputUIAccept) == true || im.GetButtonDown(FSTokens.InputUICancel) == true) && !blockSkip)
                {
                    Debug.Log("Skip requested! " + blockSkip);
                    //If we skip to the end of the dailog, just go ahead and execute all outstanding commands.
                    for (int i = commandIndex; i < inlineCommandStrings.Length; ++i)
                    {
                        yield return(parseInlineCommand(inlineCommandStrings[i], true));
                    }
                    lineText.text = displayText.ToString();
                    yield return(new WaitForSeconds(textSpeed));

                    break;
                }

                while (openStyleTags.ContainsKey(currCharIndex))
                {
                    //Add the start tag
                    buildDisplayString(stringBuilder, openStyleTags[currCharIndex].openTag, closeTagLength);
                    Debug.Log("Adding open tag: " + openStyleTags[currCharIndex].openTag);
                    //Add the ending tag
                    buildDisplayString(stringBuilder, openStyleTags[currCharIndex].closeTag, closeTagLength);
                    Debug.Log("Adding closed tag: " + openStyleTags[currCharIndex].closeTag);
                    closeTagLength += openStyleTags[currCharIndex].closeTag.Length;

                    Debug.Log("Close tag length :" + closeTagLength);
                    //Advance the iterator and char count past the start tag.
                    int oldCharIndex = currCharIndex;
                    for (int i = 0; i < openStyleTags[oldCharIndex].openTag.Length; ++i)
                    {
                        ++currCharIndex;
                        enumerator.MoveNext();
                    }
                    c = enumerator.Current;
                }
                while (closedStyleTags.ContainsKey(currCharIndex))
                {
                    //Skip ahead past the end of the closing tag. There's no need to add anything to the string, since the closing tag has been there the whole time.
                    Debug.Log("Closed tag found, skipping past it");
                    int oldCharIndex = currCharIndex;
                    closeTagLength -= closedStyleTags[oldCharIndex].Length;
                    Debug.Log("Close tag length :" + closeTagLength);
                    for (int i = 0; i < closedStyleTags[oldCharIndex].Length; ++i)
                    {
                        ++currCharIndex;
                        enumerator.MoveNext();
                    }
                    //We're done with this tag. Next time we encounter one it'll be a new pair.
                    if (currCharIndex <= displayText.Length - 1)
                    {
                        c = enumerator.Current;
                    }
                }

                if (currCharIndex <= displayText.Length - 1)
                {
                    buildDisplayString(stringBuilder, c, closeTagLength);
                    ++currCharIndex;
                }

                lineText.text = stringBuilder.ToString();
                yield return(new WaitForSeconds(textSpeed));
            }
        }
        else
        {
            // Display the line immediately if textSpeed == 0
            lineText.text = displayText.ToString();
            for (int i = 0; i < inlineCommandStrings.Length; ++i)
            {
                //Execute all of the inline commands
                yield return(parseInlineCommand(inlineCommandStrings[i], true));
            }
        }

        // Show the 'press any key' prompt when done, if we have one
        if (continuePrompt != null)
        {
            continuePrompt.SetActive(true);
        }

        // Wait for any user input
        while (im.GetButtonDown(FSTokens.InputUIAccept) == false && im.GetButtonDown(FSTokens.InputUICancel) == false)
        {
            yield return(null);
        }

        // Hide the text and prompt
        lineText.gameObject.SetActive(false);

        if (continuePrompt != null)
        {
            continuePrompt.SetActive(false);
        }
    }