示例#1
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();
        }
示例#2
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.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)
            {
                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
                    {
                        // Unrecognized CustomTag Type. Should we error here?
                    }
                }
                else
                {
                    printedCharCount++;

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