public virtual IEnumerator Write(string content, bool clear, bool waitForInput, bool stopAudio, AudioClip audioClip, Action onComplete) { if (clear) { this.text = ""; } if (!HasTextObject()) { yield break; } // If this clip is null then WriterAudio will play the default sound effect (if any) NotifyStart(audioClip); string tokenText = content; if (waitForInput) { tokenText += "{wi}"; } ITextTagParser tagParser = new TextTagParser(); List <TextTagToken> tokens = tagParser.Tokenize(tokenText); gameObject.SetActive(true); yield return(StartCoroutine(ProcessTokens(tokens, stopAudio, onComplete))); }
public virtual void Write(string content, bool clear, bool waitForInput, AudioClip audioClip, Action onComplete) { if (clear) { this.text = ""; } if (!HasTextObject()) { return; } // If this clip is null then WriterAudio will play the default sound effect (if any) NotifyStart(audioClip); string tokenText = content; if (waitForInput) { tokenText += "{wi}"; } TextTagParser tagParser = new TextTagParser(); List <TextTagParser.Token> tokens = tagParser.Tokenize(tokenText); StartCoroutine(ProcessTokens(tokens, onComplete)); }
/// <summary> /// Writes text using a typewriter effect to a UI text object. /// </summary> /// <param name="content">Text to be written</param> /// <param name="clear">If true clears the previous text.</param> /// <param name="waitForInput">Writes the text and then waits for player input before calling onComplete.</param> /// <param name="stopAudio">Stops any currently playing audioclip.</param> /// <param name="waitForVO">Wait for the Voice over to complete before proceeding</param> /// <param name="audioClip">Audio clip to play when text starts writing.</param> /// <param name="onComplete">Callback to call when writing is finished.</param> public virtual IEnumerator Write(string content, bool clear, bool waitForInput, bool stopAudio, bool waitForVO, AudioClip audioClip, System.Action onComplete) { if (clear) { textAdapter.Text = ""; visibleCharacterCount = 0; } if (!textAdapter.HasTextObject()) { yield break; } // If this clip is null then WriterAudio will play the default sound effect (if any) NotifyStart(audioClip); string tokenText = TextVariationHandler.SelectVariations(content); if (waitForInput) { tokenText += "{wi}"; } if (waitForVO) { tokenText += "{wvo}"; } List <TextTagToken> tokens = TextTagParser.Tokenize(tokenText); gameObject.SetActive(true); yield return(StartCoroutine(ProcessTokens(tokens, stopAudio, onComplete))); }
static public void DrawTagHelpLabel() { string tagsText = TextTagParser.GetTagHelp(); if (CustomTag.activeCustomTags.Count > 0) { tagsText += "\n\n\t-------- CUSTOM TAGS --------"; List <Transform> activeCustomTagGroup = new List <Transform>(); foreach (CustomTag ct in CustomTag.activeCustomTags) { if (ct.transform.parent != null) { if (!activeCustomTagGroup.Contains(ct.transform.parent.transform)) { activeCustomTagGroup.Add(ct.transform.parent.transform); } } else { activeCustomTagGroup.Add(ct.transform); } } foreach (Transform parent in activeCustomTagGroup) { string tagName = parent.name; string tagStartSymbol = ""; string tagEndSymbol = ""; CustomTag parentTag = parent.GetComponent <CustomTag>(); if (parentTag != null) { tagName = parentTag.name; tagStartSymbol = parentTag.tagStartSymbol; tagEndSymbol = parentTag.tagEndSymbol; } tagsText += "\n\n\t" + tagStartSymbol + " " + tagName + " " + tagEndSymbol; foreach (Transform child in parent) { tagName = child.name; tagStartSymbol = ""; tagEndSymbol = ""; CustomTag childTag = child.GetComponent <CustomTag>(); if (childTag != null) { tagName = childTag.name; tagStartSymbol = childTag.tagStartSymbol; tagEndSymbol = childTag.tagEndSymbol; } tagsText += "\n\t " + tagStartSymbol + " " + tagName + " " + tagEndSymbol; } } } tagsText += "\n"; float pixelHeight = EditorStyles.miniLabel.CalcHeight(new GUIContent(tagsText), EditorGUIUtility.currentViewWidth); EditorGUILayout.SelectableLabel(tagsText, GUI.skin.GetStyle("HelpBox"), GUILayout.MinHeight(pixelHeight)); }
static public void DrawTagHelpLabel() { string tagsText = ""; tagsText += "\n"; tagsText += TextTagParser.GetTagHelp(); float pixelHeight = EditorStyles.miniLabel.CalcHeight(new GUIContent(tagsText), EditorGUIUtility.currentViewWidth); EditorGUILayout.SelectableLabel(tagsText, GUI.skin.GetStyle("HelpBox"), GUILayout.MinHeight(pixelHeight)); }
public void TextTagParser_AudioWaitBug() { var textTagParser = new TextTagParser(); // Parse an example string, generate correct sequence of tags List<TextTagParser.Token> tokens = textTagParser.Tokenize("Play sound{audio=BeepSound}{w=1} Play loop{audioloop=BeepSound}{w=3} Stop{audiostop=BeepSound}"); int i = 0; Assert.That(tokens[i].type == TextTagParser.TokenType.Words); Assert.That(tokens[i].paramList[0] == "Play sound"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Audio); Assert.That(tokens[i].paramList[0] == "BeepSound"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Wait); Assert.That(tokens[i].paramList[0] == "1"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Words); Assert.That(tokens[i].paramList[0] == " Play loop"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.AudioLoop); Assert.That(tokens[i].paramList[0] == "BeepSound"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Wait); Assert.That(tokens[i].paramList[0] == "3"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Words); Assert.That(tokens[i].paramList[0] == " Stop"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.AudioStop); Assert.That(tokens[i].paramList[0] == "BeepSound"); Assert.That(tokens.Count == 8); }
public void TextTagParser_Parser() { var textTagParser = new TextTagParser(); // Parse an example string, generate correct sequence of tags List<TextTagParser.Token> tokens = textTagParser.Tokenize("Words " + "{b}bold test{/b}" + "{i}italic test{/i}" + "{color=red}color test{/color}" + "{w}{w=0.5}" + "{wi}{wc}" + "{wp}{wp=0.5}{/wp}" + "{c}" + "{s}{s=60}{/s}" + "{x}{m=Message}" + "{vpunch=0.5}" + "{hpunch=0.5}" + "{punch=0.5}" + "{flash=0.5}" + "{audio=Sound}" + "{audioloop=Sound}" + "{audiopause=Sound}" + "{audiostop=Sound}"); int i = 0; Assert.That(tokens[i].type == TextTagParser.TokenType.Words); Assert.That(tokens[i].paramList[0] == "Words "); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.BoldStart); Assert.That(tokens[i].paramList.Count == 0); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Words); Assert.That(tokens[i].paramList[0] == "bold test"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.BoldEnd); Assert.That(tokens[i].paramList.Count == 0); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.ItalicStart); Assert.That(tokens[i].paramList.Count == 0); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Words); Assert.That(tokens[i].paramList[0] == "italic test"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.ItalicEnd); Assert.That(tokens[i].paramList.Count == 0); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.ColorStart); Assert.That(tokens[i].paramList[0] == "red"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Words); Assert.That(tokens[i].paramList[0] == "color test"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.ColorEnd); Assert.That(tokens[i].paramList.Count == 0); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Wait); Assert.That(tokens[i].paramList.Count == 0); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Wait); Assert.That(tokens[i].paramList[0] == "0.5"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.WaitForInputNoClear); Assert.That(tokens[i].paramList.Count == 0); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.WaitForInputAndClear); Assert.That(tokens[i].paramList.Count == 0); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.WaitOnPunctuationStart); Assert.That(tokens[i].paramList.Count == 0); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.WaitOnPunctuationStart); Assert.That(tokens[i].paramList[0] == "0.5"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.WaitOnPunctuationEnd); Assert.That(tokens[i].paramList.Count == 0); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Clear); Assert.That(tokens[i].paramList.Count == 0); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.SpeedStart); Assert.That(tokens[i].paramList.Count == 0); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.SpeedStart); Assert.That(tokens[i].paramList[0] == "60"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.SpeedEnd); Assert.That(tokens[i].paramList.Count == 0); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Exit); Assert.That(tokens[i].paramList.Count == 0); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Message); Assert.That(tokens[i].paramList[0] == "Message"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.VerticalPunch); Assert.That(tokens[i].paramList[0] == "0.5"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.HorizontalPunch); Assert.That(tokens[i].paramList[0] == "0.5"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Punch); Assert.That(tokens[i].paramList[0] == "0.5"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Flash); Assert.That(tokens[i].paramList[0] == "0.5"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.Audio); Assert.That(tokens[i].paramList[0] == "Sound"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.AudioLoop); Assert.That(tokens[i].paramList[0] == "Sound"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.AudioPause); Assert.That(tokens[i].paramList[0] == "Sound"); i++; Assert.That(tokens[i].type == TextTagParser.TokenType.AudioStop); Assert.That(tokens[i].paramList[0] == "Sound"); Assert.That(tokens.Count == 31); }
public virtual void Write(string content, bool clear, bool waitForInput, AudioClip audioClip, Action onComplete) { if (clear) { this.text = ""; } if (!HasTextObject()) { return; } // If this clip is null then WriterAudio will play the default sound effect (if any) NotifyStart(audioClip); string tokenText = content; if (waitForInput) { tokenText += "{wi}"; } TextTagParser tagParser = new TextTagParser(); List<TextTagParser.Token> tokens = tagParser.Tokenize(tokenText); StartCoroutine(ProcessTokens(tokens, onComplete)); }
protected virtual IEnumerator DoWords(List<string> paramList, TextTagParser.TokenType previousTokenType) { if (!CheckParamCount(paramList, 1)) { yield break; } string param = paramList[0]; // Trim whitespace after a {wc} or {c} tag if (previousTokenType == TextTagParser.TokenType.WaitForInputAndClear || previousTokenType == TextTagParser.TokenType.Clear) { param = param.TrimStart(' ', '\t', '\r', '\n'); } string startText = text; string openText = OpenMarkup(); string closeText = CloseMarkup(); float timeAccumulator = Time.deltaTime; for (int i = 0; i < param.Length; ++i) { // Exit immediately if the exit flag has been set if (exitFlag) { break; } string left = ""; string right = ""; PartitionString(writeWholeWords, param, i, out left, out right); text = ConcatenateString(startText, openText, closeText, left, right); NotifyGlyph(); // No delay if user has clicked and Instant Complete is enabled if (instantComplete && inputFlag) { continue; } // Punctuation pause if (left.Length > 0 && right.Length > 0 && IsPunctuation(left.Substring(left.Length - 1)[0])) { yield return StartCoroutine(DoWait(currentPunctuationPause)); } // Delay between characters if (currentWritingSpeed > 0f) { if (timeAccumulator > 0f) { timeAccumulator -= 1f / currentWritingSpeed; } else { yield return new WaitForSeconds(1f / currentWritingSpeed); } } } }
public virtual IEnumerator Write(string content, bool clear, bool waitForInput, bool stopAudio, AudioClip audioClip, Action onComplete) { if (clear) { this.text = ""; } if (!HasTextObject()) { yield break; } // If this clip is null then WriterAudio will play the default sound effect (if any) NotifyStart(audioClip); string tokenText = content; if (waitForInput) { tokenText += "{wi}"; } TextTagParser tagParser = new TextTagParser(); List<TextTagParser.Token> tokens = tagParser.Tokenize(tokenText); gameObject.SetActive(true); yield return StartCoroutine(ProcessTokens(tokens, stopAudio, onComplete)); }