示例#1
0
        private IEnumerator TypeTextCharByChar(string text, int skipChars, int printAmount)
        {
            this.taglessText = TextTagParser.RemoveAllTags(text);
            var totalChars = this.taglessText.Length;

            this.PrintedCharacters = Mathf.Clamp(skipChars, 0, totalChars);
            this.TextComponent.SetText(TextTagParser.RemoveCustomTags(text));

            while (this.PrintedCharacters < totalChars)
            {
                this.PrintedCharacters = Mathf.Clamp(this.PrintedCharacters + printAmount, 0, totalChars);
                var index = this.PrintedCharacters - 1;
                this.TextComponent.maxVisibleCharacters = this.PrintedCharacters;

                UpdateMeshAndAnims();
                OnCharacterPrinted(this.taglessText[index].ToString());

                var delay = this.characterPrintDelays[index];

                if (this.useUnscaledTime)
                {
                    yield return(new WaitForSecondsRealtime(delay));
                }
                else
                {
                    yield return(new WaitForSeconds(delay));
                }
            }

            this.typeTextCoroutine = null;
            OnTypewritingComplete();
        }
示例#2
0
        void GetLastCharData(InkTypewriterText typewriterText)
        {
            string taglessText       = TextTagParser.RemoveAllTags(currentText);
            int    totalPrintedChars = taglessText.Length;
            int    lastChar          = totalPrintedChars - 1;

            //typewriterText.TagSetSpeaker(this.speakerAssetTriggers[totalPrintedChars - 1]);
            //typewriterText.TagSetExpression(this.characterExpressionTriggers[totalPrintedChars - 1]);
            //typewriterText.TagSetAlignment(this.alignmentTriggers[totalPrintedChars - 1]);

            this.UpdateMeshAndAnims();

            this.OnCharacterPrinted(taglessText[totalPrintedChars - 1].ToString());



            if (this.speakerAssetTriggers[totalPrintedChars - 1] != typewriterText.changeSpeaker)
            {
                typewriterText.TagSetSpeaker(this.speakerAssetTriggers[totalPrintedChars - 1]);
            }

            if (this.characterExpressionTriggers[totalPrintedChars - 1] != typewriterText.changeExpression)
            {
                typewriterText.TagSetExpression(this.characterExpressionTriggers[totalPrintedChars - 1]);
            }

            if (this.characterExpressionTriggers[totalPrintedChars - 1] != (int)typewriterText.dialogueBoxPosition)
            {
                typewriterText.TagSetAlignment(this.alignmentTriggers[totalPrintedChars - 1]);
            }

            if (this.invokeTriggers[totalPrintedChars - 1] != null)
            {
                typewriterText.Invoke(this.invokeTriggers[totalPrintedChars - 1], 0);
            }

            if (this.refreshTriggers[totalPrintedChars - 1] != false)
            {
                typewriterText.RefreshSpeaker();
            }
        }
示例#3
0
        private IEnumerator TypeTextCharByChar(string text)
        {
            string taglessText       = TextTagParser.RemoveAllTags(text);
            int    totalPrintedChars = taglessText.Length;

            int currPrintedChars = 1;

            this.TextComponent.text = TextTagParser.RemoveCustomTags(text);
            do
            {
                this.TextComponent.maxVisibleCharacters = currPrintedChars;
                this.UpdateMeshAndAnims();

                this.OnCharacterPrinted(taglessText[currPrintedChars - 1].ToString());
                yield return(new WaitForSeconds(this.characterPrintDelays[currPrintedChars - 1]));

                ++currPrintedChars;
            }while (currPrintedChars <= totalPrintedChars);

            this.typeTextCoroutine = null;
            this.OnTypewritingComplete();
        }
示例#4
0
        private IEnumerator TypeTextCharByChar(string text)
        {
            this.TextComponent.text = TextTagParser.RemoveCustomTags(text);
            for (int numPrintedCharacters = 0; numPrintedCharacters < this.charactersToType.Count; ++numPrintedCharacters)
            {
                this.TextComponent.maxVisibleCharacters = numPrintedCharacters + 1;
                this.UpdateMeshAndAnims();

                var printedChar = this.charactersToType[numPrintedCharacters];
                this.OnCharacterPrinted(printedChar.ToString());

                if (this.useUnscaledTime)
                {
                    yield return(new WaitForSecondsRealtime(printedChar.Delay));
                }
                else
                {
                    yield return(new WaitForSeconds(printedChar.Delay));
                }
            }

            this.typeTextCoroutine = null;
            this.OnTypewritingComplete();
        }
示例#5
0
        /// <summary>
        /// Calculates print delays for every visible character in the string.
        /// Processes delay tags, punctuation delays, and default delays
        /// Also processes shake and curve animations and spawns
        /// the appropriate TextAnimation components
        /// </summary>
        /// <param name="text">Full text string with tags</param>
        private void ProcessCustomTags(string text)
        {
            this.characterPrintDelays        = new List <float>(text.Length);
            this.speakerAssetTriggers        = new List <int>(text.Length);
            this.characterExpressionTriggers = new List <int>(text.Length);
            this.alignmentTriggers           = new List <int>(text.Length);
            this.invokeTriggers  = new List <string>(text.Length);
            this.refreshTriggers = new List <bool>(text.Length);


            this.animations = new List <TextAnimation>();

            var textAsSymbolList = TextTagParser.CreateSymbolListFromText(text);

            int    printedCharCount   = 0;
            int    customTagOpenIndex = 0;
            string customTagParam     = "";
            float  nextDelay          = this.defaultPrintDelay;

            int    nextExpression = this.defaultExpression;
            int    nextSpeaker    = this.defaultSpeaker;
            int    nextAlignment  = this.defaultAlignment;
            string nextInvoke     = this.defaultInvoke;
            bool   nextTrigger    = false;

            foreach (var symbol in textAsSymbolList)
            {
                if (symbol.IsTag)
                {
                    // TODO - Verification that custom tags are not nested, b/c that will not be handled gracefully
                    if (symbol.Tag.TagType == TextTagParser.CustomTags.Delay)
                    {
                        if (symbol.Tag.IsClosingTag)
                        {
                            nextDelay = this.defaultPrintDelay;
                        }
                        else
                        {
                            nextDelay = symbol.GetFloatParameter(this.defaultPrintDelay);
                        }
                    }
                    else if (symbol.Tag.TagType == TextTagParser.CustomTags.Anim ||
                             symbol.Tag.TagType == TextTagParser.CustomTags.Animation)
                    {
                        if (symbol.Tag.IsClosingTag)
                        {
                            // Add a TextAnimation component to process this animation
                            TextAnimation anim = null;
                            if (this.IsAnimationShake(customTagParam))
                            {
                                anim = gameObject.AddComponent <ShakeAnimation>();
                                ((ShakeAnimation)anim).LoadPreset(this.shakeLibrary, customTagParam);
                            }
                            else if (this.IsAnimationCurve(customTagParam))
                            {
                                anim = gameObject.AddComponent <CurveAnimation>();
                                ((CurveAnimation)anim).LoadPreset(this.curveLibrary, customTagParam);
                            }
                            else
                            {
                                // Could not find animation. Should we error here?
                            }

                            anim.SetCharsToAnimate(customTagOpenIndex, printedCharCount - 1);
                            anim.enabled = true;
                            this.animations.Add(anim);
                        }
                        else
                        {
                            customTagOpenIndex = printedCharCount;
                            customTagParam     = symbol.Tag.Parameter;
                        }
                    }
                    else if (symbol.Tag.TagType == TextTagParser.CustomTags.Expression)
                    {
                        nextExpression = symbol.GetIntParameter(this.defaultExpression);
                        nextTrigger    = true;
                    }
                    else if (symbol.Tag.TagType == TextTagParser.CustomTags.Speaker)
                    {
                        nextSpeaker = symbol.GetIntParameter(this.defaultSpeaker);
                        nextTrigger = true;
                    }
                    else if (symbol.Tag.TagType == TextTagParser.CustomTags.Alignment)
                    {
                        nextAlignment = symbol.GetIntParameter(this.defaultAlignment);
                        nextTrigger   = true;
                    }
                    else if (symbol.Tag.TagType == TextTagParser.CustomTags.Invoke)
                    {
                        nextInvoke  = symbol.GetStringParameter(this.defaultInvoke);
                        nextTrigger = true;
                    }

                    else
                    {
                        // Unrecognized CustomTag Type. Should we error here?
                    }
                }
                else
                {
                    printedCharCount++;


                    if (punctutationCharacters.Contains(symbol.Character))
                    {
                        this.characterPrintDelays.Add(nextDelay * PunctuationDelayMultiplier);
                    }
                    else
                    {
                        this.characterPrintDelays.Add(nextDelay);
                    }

                    this.speakerAssetTriggers.Add(nextSpeaker);
                    this.characterExpressionTriggers.Add(nextExpression);
                    this.alignmentTriggers.Add(nextAlignment);
                    this.invokeTriggers.Add(nextInvoke);

                    this.refreshTriggers.Add(nextTrigger);

                    nextInvoke = null;
                }
            }
        }
示例#6
0
        private IEnumerator TypeTextCharByChar(string text, InkTypewriterText typewriterText)
        {
            string taglessText       = TextTagParser.RemoveAllTags(text);
            int    totalPrintedChars = taglessText.Length;

            int currPrintedChars = 1;

            this.TextComponent.text = TextTagParser.RemoveCustomTags(text);

            typewriterText.TagSetSpeaker(this.speakerAssetTriggers[currPrintedChars]);

            typewriterText.TagSetExpression(this.characterExpressionTriggers[currPrintedChars]);

            if (this.invokeTriggers[currPrintedChars] != null)
            {
                typewriterText.Invoke(this.invokeTriggers[currPrintedChars], 0);
            }

            typewriterText.TagSetAlignment(this.alignmentTriggers[currPrintedChars]);
            typewriterText.RefreshSpeaker();

            do
            {
                this.TextComponent.maxVisibleCharacters = currPrintedChars;
                this.UpdateMeshAndAnims();

                this.OnCharacterPrinted(taglessText[currPrintedChars - 1].ToString());

                if (this.speakerAssetTriggers[currPrintedChars - 1] != typewriterText.changeSpeaker)
                {
                    typewriterText.TagSetSpeaker(this.speakerAssetTriggers[currPrintedChars - 1]);
                }

                if (this.characterExpressionTriggers[currPrintedChars - 1] != typewriterText.changeExpression)
                {
                    typewriterText.TagSetExpression(this.characterExpressionTriggers[currPrintedChars - 1]);
                }

                if (this.characterExpressionTriggers[currPrintedChars - 1] != (int)typewriterText.dialogueBoxPosition)
                {
                    typewriterText.TagSetAlignment(this.alignmentTriggers[currPrintedChars - 1]);
                }

                if (this.invokeTriggers[currPrintedChars - 1] != null)
                {
                    typewriterText.Invoke(this.invokeTriggers[currPrintedChars - 1], 0);
                }

                if (this.refreshTriggers[currPrintedChars - 1] != false)
                {
                    typewriterText.RefreshSpeaker();
                }


                yield return(new WaitForSecondsRealtime(this.characterPrintDelays[currPrintedChars - 1]));

                ++currPrintedChars;
            }while (currPrintedChars <= totalPrintedChars);

            this.typeTextCoroutine = null;
            this.OnTypewritingComplete();
        }
示例#7
0
        /// <summary>
        /// Calculates print delays for every visible character in the string.
        /// Processes delay tags, punctuation delays, and default delays
        /// Also processes shake and curve animations and spawns
        /// the appropriate TextAnimation components
        /// </summary>
        /// <param name="text">Full text string with tags</param>
        private void ProcessCustomTags(string text, float printDelay)
        {
            TextTagParser.CreateSymbolListFromText(text, this.textAsSymbolList);

            ProcessCustomTags(printDelay);
        }
示例#8
0
        /// <summary>
        /// Calculates print delays for every visible character in the string.
        /// Processes delay tags, punctuation delays, and default delays
        /// Also processes shake and curve animations and spawns
        /// the appropriate TextAnimation components
        /// </summary>
        /// <param name="text">Full text string with tags</param>
        private void ProcessTags(string text)
        {
            this.charactersToType = new List <TypableCharacter>();
            this.animations       = new List <TextAnimation>();
            var textAsSymbolList = TextTagParser.CreateSymbolListFromText(text);

            int    printedCharCount   = 0;
            int    customTagOpenIndex = 0;
            string customTagParam     = "";
            float  nextDelay          = this.defaultPrintDelay;

            foreach (var symbol in textAsSymbolList)
            {
                // Sprite prints a character so we need to throw it out and treat it like a character
                if (symbol.IsTag && !symbol.IsReplacedWithSprite)
                {
                    // TODO - Verification that custom tags are not nested, b/c that will not be handled gracefully
                    if (symbol.Tag.TagType == TextTagParser.CustomTags.Delay)
                    {
                        if (symbol.Tag.IsClosingTag)
                        {
                            nextDelay = this.defaultPrintDelay;
                        }
                        else
                        {
                            nextDelay = symbol.GetFloatParameter(this.defaultPrintDelay);
                        }
                    }
                    else if (symbol.Tag.TagType == TextTagParser.CustomTags.Anim ||
                             symbol.Tag.TagType == TextTagParser.CustomTags.Animation)
                    {
                        if (symbol.Tag.IsClosingTag)
                        {
                            // Add a TextAnimation component to process this animation
                            TextAnimation anim = null;
                            if (this.IsAnimationShake(customTagParam))
                            {
                                anim = gameObject.AddComponent <ShakeAnimation>();
                                ((ShakeAnimation)anim).LoadPreset(this.shakeLibrary, customTagParam);
                            }
                            else if (this.IsAnimationCurve(customTagParam))
                            {
                                anim = gameObject.AddComponent <CurveAnimation>();
                                ((CurveAnimation)anim).LoadPreset(this.curveLibrary, customTagParam);
                            }
                            else
                            {
                                // Could not find animation. Should we error here?
                            }

                            anim.UseUnscaledTime = this.useUnscaledTime;
                            anim.SetCharsToAnimate(customTagOpenIndex, printedCharCount - 1);
                            anim.enabled = true;
                            this.animations.Add(anim);
                        }
                        else
                        {
                            customTagOpenIndex = printedCharCount;
                            customTagParam     = symbol.Tag.Parameter;
                        }
                    }
                    else
                    {
                        // Tag type is likely a Unity tag, but it might be something we don't know... could error if unrecognized.
                    }
                }
                else
                {
                    printedCharCount++;

                    TypableCharacter characterToType = new TypableCharacter();
                    if (symbol.IsTag && symbol.IsReplacedWithSprite)
                    {
                        characterToType.IsSprite = true;
                    }
                    else
                    {
                        characterToType.Char = symbol.Character;
                    }

                    characterToType.Delay = nextDelay;
                    if (punctutationCharacters.Contains(symbol.Character))
                    {
                        characterToType.Delay *= PunctuationDelayMultiplier;
                    }

                    this.charactersToType.Add(characterToType);
                }
            }
        }