/// <summary> /// Calculates print delays for every visible character in the string. /// Processes shake and curve animations and spawns /// the appropriate TextAnimation components /// </summary> private void ProcessCustomTags(float printDelay) { this.characterPrintDelays.Clear(); this.animations.Clear(); var printedCharCount = 0; var customTagOpenIndex = 0; var customTagParam = string.Empty; var nextDelay = printDelay; var punctuations = GetPunctutations(); var punctuationDelayMultiplier = GetPunctuationDelayMultiplier(); foreach (var symbol in this.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 = printDelay; } else { nextDelay = symbol.GetFloatParameter(printDelay); } } else if (symbol.Tag.TagType == TextTagParser.CustomTags.Speed) { if (symbol.Tag.IsClosingTag) { nextDelay = printDelay; } else { var speed = symbol.GetFloatParameter(1f); if (Mathf.Approximately(speed, 0f)) { nextDelay = printDelay; } else if (speed < 0f) { nextDelay = printDelay * Mathf.Abs(speed); } else if (speed > 0f) { nextDelay = printDelay / Mathf.Abs(speed); } else { nextDelay = printDelay; } } } 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 (IsAnimationShake(customTagParam)) { anim = this.gameObject.AddComponent <ShakeAnimation>(); ((ShakeAnimation)anim).LoadPreset(this.shakeLibrary, customTagParam); } else if (IsAnimationCurve(customTagParam)) { anim = this.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 { // Unrecognized CustomTag Type. Should we error here? } } else { printedCharCount++; if (punctuations.Contains(symbol.Character)) { this.characterPrintDelays.Add(nextDelay * punctuationDelayMultiplier); } else { this.characterPrintDelays.Add(nextDelay); } } } }
/// <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; } } }
/// <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); } } }