Пример #1
0
        private IEnumerator Typing(string[] subTexts, TMP_Text txt)
        {
            isTyping = true;
            speed    = defaultTypingSpeed;
            for (int i = 0; i < subTexts.Length; i++)
            {
                if (i % 2 == 1)
                {
                    yield return(EvaluateTag(subTexts[i]));
                }
                else
                {
                    int counter = 0;

                    while (counter < subTexts[i].Length)
                    {
                        txt.maxVisibleCharacters++;
                        counter++;
                        yield return(new WaitForSeconds(1 / speed));
                    }
                    yield return(null);
                }
            }
            isTyping = false;
            onLineFinish.Invoke();
        }
Пример #2
0
 private void NextLine()
 {
     if (lineIndex == conversation.lines.Length - 1)
     {
         Debug.Log("<color=yellow>Line Skipped</color>");
         onConversationFinish.Invoke();
         return;
     }
     else
     {
         lineIndex++;
         StartTyping(lineIndex);
     }
 }
Пример #3
0
 private void NextLine()
 {
     if (parser.IsEndNode(currentNode))
     {
         Debug.Log("<color=red>Dialogue End</color>");
         onConversationFinish.Invoke();
         return;
     }
     else
     {
         currentNode = parser.GetNextNode(currentNode);
         if (!currentNode.isChoiceNode)
         {
             StartTyping(currentNode.Text);
         }
         else
         {
             NextLine();
             Debug.Log("Choice Node");
         }
     }
 }
Пример #4
0
        public void ReadText(string newText)
        {
            text = string.Empty;

            string[] subTexts = newText.Split('<', '>');

            string displayText = "";

            for (int i = 0; i < subTexts.Length; i++)
            {
                if (i % 2 == 0)
                {
                    displayText += subTexts[i];
                }
                else if (!isCustomTag(subTexts[i].Replace(" ", "")))
                {
                    displayText += $"<{subTexts[i]}>";
                }
            }

            bool isCustomTag(string tag)
            {
                return(tag.StartsWith("speed=") || tag.StartsWith("pause="));
            }

            text = displayText;
            maxVisibleCharacters = 0;
            StartCoroutine(Read());

            IEnumerator Read()
            {
                int subCounter     = 0;
                int visibleCounter = 0;

                while (subCounter < subTexts.Length)
                {
                    if (subCounter % 2 == 1)
                    {
                        yield return(EvaluateTag(subTexts[subCounter].Replace(" ", "")));
                    }
                    else
                    {
                        while (visibleCounter < subTexts[subCounter].Length)
                        {
                            onTextReveal.Invoke(subTexts[subCounter][visibleCounter]);
                            visibleCounter++;
                            maxVisibleCharacters++;
                            yield return(new WaitForSeconds(1f / speed));
                        }
                        visibleCounter = 0;
                    }
                    subCounter++;
                }
                yield return(null);

                WaitForSeconds EvaluateTag(string tag)
                {
                    if (tag.Length > 0)
                    {
                        if (tag.StartsWith("speed="))
                        {
                            speed = float.Parse(tag.Split('=')[1]);
                        }
                        else if (tag.StartsWith("pause="))
                        {
                            return(new WaitForSeconds(float.Parse(tag.Split('=')[1])));
                        }
                    }
                    return(null);
                }

                onDialogueFinish.Invoke();
            }
        }
Пример #5
0
        public void ReadText(string newText)
        {
            text = string.Empty;
            // split the whole text into parts based off the <> tags
            // even numbers in the array are text, odd numbers are tags
            string[] subTexts = newText.Split('<', '>');

            // textmeshpro still needs to parse its built-in tags, so we only include noncustom tags
            string displayText = "";

            for (int i = 0; i < subTexts.Length; i++)
            {
                if (i % 2 == 0)
                {
                    displayText += subTexts[i];
                }
                else if (!isCustomTag(subTexts[i].Replace(" ", "")))
                {
                    displayText += $"<{subTexts[i]}>";
                }
            }
            // check to see if a tag is our own
            bool isCustomTag(string tag)
            {
                return(tag.StartsWith("speed=") || tag.StartsWith("pause=") || tag.StartsWith("emotion=") || tag.StartsWith("action"));
            }

            // send that string to textmeshpro and hide all of it, then start reading
            text = displayText;
            maxVisibleCharacters = 0;
            StartCoroutine(Read());

            IEnumerator Read()
            {
                int subCounter     = 0;
                int visibleCounter = 0;

                while (subCounter < subTexts.Length)
                {
                    // if
                    if (subCounter % 2 == 1)
                    {
                        yield return(EvaluateTag(subTexts[subCounter].Replace(" ", "")));
                    }
                    else
                    {
                        while (visibleCounter < subTexts[subCounter].Length)
                        {
                            onTextReveal.Invoke(subTexts[subCounter][visibleCounter]);
                            visibleCounter++;
                            maxVisibleCharacters++;
                            yield return(new WaitForSeconds(1f / speed));
                        }
                        visibleCounter = 0;
                    }
                    subCounter++;
                }
                yield return(null);

                WaitForSeconds EvaluateTag(string tag)
                {
                    if (tag.Length > 0)
                    {
                        if (tag.StartsWith("speed="))
                        {
                            speed = float.Parse(tag.Split('=')[1]);
                        }
                        else if (tag.StartsWith("pause="))
                        {
                            return(new WaitForSeconds(float.Parse(tag.Split('=')[1])));
                        }
                        else if (tag.StartsWith("emotion="))
                        {
                            onEmotionChange.Invoke((Emotion)System.Enum.Parse(typeof(Emotion), tag.Split('=')[1]));
                        }
                    }
                    return(null);
                }

                onDialogueFinish.Invoke();
            }
        }
Пример #6
0
        public void ReadText(string newText)
        {
            text = string.Empty;

            // split the whole text into parts based off the <> tags
            // even numbers in the array are text, odd numbers are tags
            string[] subTexts = newText.Split('/', '/');

            // textmeshpro still needs to parse its built-in tags, so we only include noncustom tags
            string displayText = "";

            for (int i = 0; i < subTexts.Length; i++)
            {
                if (i % 2 == 0)
                {
                    displayText += subTexts[i];
                }
                else if (!isCustomTag(subTexts[i].Replace(" ", "")))
                {
                    displayText += $"<{subTexts[i]}>";
                }
            }

            bool isCustomTag(string tag)
            {
                // /pose/ = char portrait change /emote/ = sprite changes
                // /new/ = new dialogue available /c/ = continue

                //add more custom tags with Shannon and pals
                return(tag.StartsWith("emote=") || tag.StartsWith("pose=") ||
                       tag.StartsWith("c") || tag.StartsWith("new"));
            }

            text = displayText;

            maxVisibleCharacters = 0;
            StartCoroutine(Read());

            IEnumerator Read()
            {
                int subCounter     = 0;
                int visibleCounter = 0;

                while (subCounter < subTexts.Length)
                {
                    if (subCounter % 2 == 1)
                    {
                        yield return(CheckTag(subTexts[subCounter].Replace(" ", "")));
                    }
                    else
                    {
                        while (visibleCounter < subTexts[subCounter].Length)
                        {
                            //onTextReveal event invocation here
                            visibleCounter++;
                            maxVisibleCharacters++;
                            yield return(new WaitForSecondsRealtime(1f / textSpeed));
                        }
                        visibleCounter = 0;
                    }
                    subCounter++;
                }
                yield return(null);

                WaitForSecondsRealtime CheckTag(string tag)
                {
                    if (tag.Length > 0)
                    {
                        if (tag.StartsWith("emote="))
                        {
                            onEmotionChange.Invoke(tag.Split('=')[1]);
                        }

                        else if (tag.StartsWith("pose="))
                        {
                            onPoseChange.Invoke(tag.Split('=')[1]);
                        }

                        else if (tag.StartsWith("c"))
                        {
                            nextDialogueBlock.Invoke();
                        }

                        else if (tag.StartsWith("new"))
                        {
                            newDialogue.Invoke();
                        }
                        //else if more tags
                    }

                    return(null);
                }

                onDialogueFinish.Invoke();
            }
        }
    public void ReadText(string newText)
    {
        text = string.Empty;
        // split the whole text into parts based off the <> tags
        // even numbers in the array are text, odd numbers are tags
        string[] subTexts = newText.Split('<', '>');

        // textmeshpro still needs to parse its built-in tags, so we only include noncustom tags
        string displayText = "";

        for (int i = 0; i < subTexts.Length; i++)
        {
            if (i % 2 == 0)
            {
                displayText += subTexts[i];
            }
            else if (!isCustomTag(subTexts[i].Replace(" ", "")))
            {
                displayText += $"<{subTexts[i]}>";
            }
        }
        // check to see if a tag is our own
        bool isCustomTag(string tag)
        {
            return(tag.StartsWith("speed=") || tag.StartsWith("pause=") || tag.StartsWith("emotion=") || tag.StartsWith("action"));
        }

        // send that string to textmeshpro and hide all of it, then start reading
        text                 = displayText;
        InstantLine          = false;
        maxVisibleCharacters = 0;
        StartCoroutine(Read());

        IEnumerator Read()
        {
            int subCounter     = 0;
            int visibleCounter = 0;

            while (subCounter < subTexts.Length)
            {
                InstantLine = false;
                //ToDo: if PARA => new dialog entry; reset maxvisible back to zero, start from next array entry
                //ToDo: Split `string` into new text bubble here
                // if custom tag
                if (subCounter % 2 == 1)
                {
                    yield return(EvaluateTag(subTexts[subCounter].Replace(" ", "")));
                }
                else
                {
                    //ToDo: if `SkipAhead()` set maxvisiblechar to reveal entire string.
                    while (visibleCounter < subTexts[subCounter].Length)
                    {
                        //ToDo: if LINE => line break; reset maxvisible from two lines of text to one, start text on new line
                        onTextReveal.Invoke(subTexts[subCounter][visibleCounter]);
                        visibleCounter++;
                        maxVisibleCharacters++;
                        //if (InstantLine) continue; else
                        yield return(new WaitForSeconds(secPerChar));
                    }
                    visibleCounter = 0;
                }
                subCounter++;
            }
            yield return(null);

            WaitForSeconds EvaluateTag(string tag)
            {
                if (tag.Length > 0)
                {
                    if (tag.StartsWith("speed="))
                    {
                        //speed = float.Parse(tag.Split('=')[1]);
                    }
                    else if (tag.StartsWith("pause="))
                    {
                        return(new WaitForSeconds(float.Parse(tag.Split('=')[1])));
                    }
                    else if (tag.StartsWith("emotion="))
                    {
                        onEmotionChange.Invoke((Emotion)System.Enum.Parse(typeof(Emotion), tag.Split('=')[1]));
                    }
                    else if (tag.StartsWith("action="))
                    {
                        onAction.Invoke(tag.Split('=')[1]);
                    }
                }
                return(null);
            }

            onDialogueFinish.Invoke();
        }
    }
Пример #8
0
 public void OnSignalRaised(Dialogue[] dialogue)     //Will do something when we raise a signal
 {
     signalEvent.Invoke(dialogue);
 }
Пример #9
0
    // TODO Rewrite Parsing of string so that we can get in some commands
    public string ParseText(string line)
    {
        string newLine = string.Empty;

        //Old Parser
        //string command = "";

        // split the whole text into parts based off the <> tags
        // even numbers in the array are text, odd numbers are tags
        string[] subTexts = line.Split('<', '>');

        // textmeshpro still needs to parse its built-in tags, so we only include noncustom tags
        string displayText = "";

        //Run through each subtext
        for (int i = 0; i < subTexts.Length; i++)
        {
            // If the number is even then we add it to the display text as text
            if (i % 2 == 0)
            {
                displayText += subTexts[i];
            }
            //If it is not a custom tag either then we add it in as a regular TMP tag
            else if (!isCustomTag(subTexts[i].Replace(" ", "")))
            {
                displayText += $"<{subTexts[i]}>";
            }
        }

        //Check if the string we are using is a custom tag
        bool isCustomTag(string tag)
        {
            return(tag.StartsWith("speed=") || tag.StartsWith("pause=") || tag.StartsWith("emotion=") || tag.StartsWith("action="));
        }

        //Create our Text Game object
        GameObject text = CreateText();

        convoLines.Add(text);
        //Get the Text Mesh Pro component
        TextMeshProUGUI tmp = text.GetComponent <TextMeshProUGUI>();

        tmp.font = textMeshFont;

        // send that string to textmeshpro and hide all of it, then start reading
        tmp.text = displayText;
        tmp.maxVisibleCharacters = 0;
        StartCoroutine(Read());

        IEnumerator Read()
        {
            int subCounter      = 0;
            int visibileCounter = 0;

            //while the amount of sub texts we've read is less than the total
            while (subCounter < subTexts.Length)
            {
                //if the sub counter is odd then we evaluate the tag
                if (subCounter % 2 == 1)
                {
                    yield return(EvaluateTag(subTexts[subCounter].Replace(" ", "")));
                }
                //If it is not then we read it out and use any of the tags weve got
                else
                {
                    while (visibileCounter < subTexts[subCounter].Length)
                    {
                        onTextReveal.Invoke(subTexts[subCounter][visibileCounter]);
                        visibileCounter++;
                        tmp.maxVisibleCharacters++;
                        yield return(new WaitForSeconds(1f / speed));
                    }

                    visibileCounter = 0;
                }
                subCounter++;
            }

            yield return(null);

            //TODO move to other classes?
            // Evaluate each of our tags
            WaitForSeconds EvaluateTag(string tag)
            {
                if (tag.Length > 0)
                {
                    if (tag.StartsWith("speed="))
                    {
                        speed = float.Parse(tag.Split('=')[1]);
                    }
                    else if (tag.StartsWith("pause="))
                    {
                        return(new WaitForSeconds(float.Parse(tag.Split('=')[1])));
                    }

                    else if (tag.StartsWith("emotion="))
                    {
                        onEmotionChange.Invoke((Emotion)System.Enum.Parse(typeof(Emotion), tag.Split('=')[1]));
                    }
                    else if (tag.StartsWith("action="))
                    {
                        onAction.Invoke(tag.Split('=')[1]);
                    }
                }

                return(null);
            }

            onDialogueFinish.Invoke();
        }

        return(newLine);
    }