// 处理Token序列 protected virtual IEnumerator ProcessTokens(List <TextTagToken> tokens, bool stopAudio, Action onComplete) { // Reset control members boldActive = false; italicActive = false; colorActive = false; sizeActive = false; colorText = ""; sizeValue = 16f; currentPunctuationPause = punctuationPause; currentWritingSpeed = writingSpeed; exitFlag = false; isWriting = true; TokenType previousTokenType = TokenType.Invalid; // 开始, // 遍历所有Token for (int i = 0; i < tokens.Count; ++i) { // 持续保持暂停 // Pause between tokens if Paused is set while (Paused) { yield return(null); } var token = tokens[i]; // Notify listeners about new token WriterSignals.DoTextTagToken(this, token, i, tokens.Count); // Update the read ahead string buffer. This contains the text for any // Word tags which are further ahead in the list. readAheadString.Length = 0; // 向后查看Token // 获取到所有的Words Token for (int j = i + 1; j < tokens.Count; ++j) { var readAheadToken = tokens[j]; // work token的paramList: // * 只有一个参数 // * 就是要显示的文本 if (readAheadToken.type == TokenType.Words && readAheadToken.paramList.Count == 1) { readAheadString.Append(readAheadToken.paramList[0]); } else if (readAheadToken.type == TokenType.WaitForInputAndClear) { break; } } // 这里有时间长度的操作,都是Coroutine操作 // 一路从SayDialog.DoSay // * Writer.Write // * Writer.ProcessTokens switch (token.type) { // 显示文本 case TokenType.Words: yield return(StartCoroutine(DoWords(token.paramList, previousTokenType))); break; // 处理<b></b> case TokenType.BoldStart: boldActive = true; break; case TokenType.BoldEnd: boldActive = false; break; // 处理斜体 case TokenType.ItalicStart: italicActive = true; break; case TokenType.ItalicEnd: italicActive = false; break; // 处理颜色 case TokenType.ColorStart: if (CheckParamCount(token.paramList, 1)) { colorActive = true; // 取出颜色参数 colorText = token.paramList[0]; } break; case TokenType.ColorEnd: colorActive = false; break; // 处理Size标签 case TokenType.SizeStart: if (TryGetSingleParam(token.paramList, 0, 16f, out sizeValue)) { sizeActive = true; } break; case TokenType.SizeEnd: sizeActive = false; break; // 等待 case TokenType.Wait: yield return(StartCoroutine(DoWait(token.paramList))); break; // 等待输入 case TokenType.WaitForInputNoClear: yield return(StartCoroutine(DoWaitForInput(false))); break; case TokenType.WaitForInputAndClear: yield return(StartCoroutine(DoWaitForInput(true))); break; // 等待语音结束 case TokenType.WaitForVoiceOver: yield return(StartCoroutine(DoWaitVO())); break; // 等待标点 case TokenType.WaitOnPunctuationStart: TryGetSingleParam(token.paramList, 0, punctuationPause, out currentPunctuationPause); break; case TokenType.WaitOnPunctuationEnd: currentPunctuationPause = punctuationPause; break; // 清屏 case TokenType.Clear: textAdapter.Text = ""; break; // 更改 // 字符出现速度 case TokenType.SpeedStart: TryGetSingleParam(token.paramList, 0, writingSpeed, out currentWritingSpeed); break; case TokenType.SpeedEnd: currentWritingSpeed = writingSpeed; break; // 结束 case TokenType.Exit: exitFlag = true; break; // 发送消息 case TokenType.Message: if (CheckParamCount(token.paramList, 1)) { Flowchart.BroadcastFungusMessage(token.paramList[0]); } break; // 震屏 case TokenType.VerticalPunch: { float vintensity; float time; TryGetSingleParam(token.paramList, 0, 10.0f, out vintensity); TryGetSingleParam(token.paramList, 1, 0.5f, out time); Punch(new Vector3(0, vintensity, 0), time); } break; case TokenType.HorizontalPunch: { float hintensity; float time; TryGetSingleParam(token.paramList, 0, 10.0f, out hintensity); TryGetSingleParam(token.paramList, 1, 0.5f, out time); Punch(new Vector3(hintensity, 0, 0), time); } break; case TokenType.Punch: { float intensity; float time; TryGetSingleParam(token.paramList, 0, 10.0f, out intensity); TryGetSingleParam(token.paramList, 1, 0.5f, out time); Punch(new Vector3(intensity, intensity, 0), time); } break; // 闪屏 case TokenType.Flash: float flashDuration; TryGetSingleParam(token.paramList, 0, 0.2f, out flashDuration); Flash(flashDuration); break; // 播放音效 case TokenType.Audio: { AudioSource audioSource = null; if (CheckParamCount(token.paramList, 1)) { audioSource = FindAudio(token.paramList[0]); } if (audioSource != null) { audioSource.PlayOneShot(audioSource.clip); } } break; // 循环播放音效 case TokenType.AudioLoop: { AudioSource audioSource = null; if (CheckParamCount(token.paramList, 1)) { audioSource = FindAudio(token.paramList[0]); } if (audioSource != null) { audioSource.Play(); audioSource.loop = true; } } break; // 暂停播放音效 case TokenType.AudioPause: { AudioSource audioSource = null; if (CheckParamCount(token.paramList, 1)) { audioSource = FindAudio(token.paramList[0]); } if (audioSource != null) { audioSource.Pause(); } } break; // 停止播放音效 case TokenType.AudioStop: { AudioSource audioSource = null; if (CheckParamCount(token.paramList, 1)) { audioSource = FindAudio(token.paramList[0]); } if (audioSource != null) { audioSource.Stop(); } } break; } // 记录当前的 // Token类型 previousTokenType = token.type; if (exitFlag) { break; } // 最后判断 } inputFlag = false; exitFlag = false; isWaitingForInput = false; isWriting = false; // 通知结束 NotifyEnd(stopAudio); if (onComplete != null) { onComplete(); } }
protected virtual IEnumerator ProcessTokens(List <TextTagToken> tokens, bool stopAudio, System.Action onComplete) { // Reset control members boldActive = false; italicActive = false; colorActive = false; sizeActive = false; WordTokensFound = tokens.Count(x => x.type == TokenType.Words); WordTokensProcessed = 0; colorText = ""; sizeValue = 16f; currentPunctuationPause = punctuationPause; currentWritingSpeed = writingSpeed; exitFlag = false; isWriting = true; TokenType previousTokenType = TokenType.Invalid; for (int i = 0; i < tokens.Count; ++i) { // Pause between tokens if Paused is set while (Paused) { yield return(null); } var token = tokens[i]; // Notify listeners about new token WriterSignals.DoTextTagToken(this, token, i, tokens.Count); // Update the read ahead string buffer. This contains the text for any // Word tags which are further ahead in the list. if (doReadAheadText && !textAdapter.SupportsHiddenCharacters()) { readAheadString.Length = 0; for (int j = i + 1; j < tokens.Count; ++j) { var readAheadToken = tokens[j]; if (readAheadToken.type == TokenType.Words && readAheadToken.paramList.Count == 1) { readAheadString.Append(readAheadToken.paramList[0]); } else if (readAheadToken.type == TokenType.WaitForInputAndClear) { break; } } } switch (token.type) { case TokenType.Words: yield return(StartCoroutine(DoWords(token.paramList, previousTokenType))); WordTokensProcessed++; break; case TokenType.BoldStart: boldActive = true; break; case TokenType.BoldEnd: boldActive = false; break; case TokenType.ItalicStart: italicActive = true; break; case TokenType.ItalicEnd: italicActive = false; break; case TokenType.ColorStart: if (CheckParamCount(token.paramList, 1)) { colorActive = true; colorText = token.paramList[0]; } break; case TokenType.ColorEnd: colorActive = false; break; case TokenType.LinkStart: if (CheckParamCount(token.paramList, 1)) { linkActive = true; linkText = token.paramList[0]; } break; case TokenType.LinkEnd: linkActive = false; break; case TokenType.SizeStart: if (TryGetSingleParam(token.paramList, 0, 16f, out sizeValue)) { sizeActive = true; } break; case TokenType.SizeEnd: sizeActive = false; break; case TokenType.Wait: yield return(StartCoroutine(DoWait(token.paramList))); break; case TokenType.WaitForInputNoClear: yield return(StartCoroutine(DoWaitForInput(false))); break; case TokenType.WaitForInputAndClear: yield return(StartCoroutine(DoWaitForInput(true))); break; case TokenType.WaitForVoiceOver: yield return(StartCoroutine(DoWaitVO())); break; case TokenType.WaitOnPunctuationStart: TryGetSingleParam(token.paramList, 0, punctuationPause, out currentPunctuationPause); break; case TokenType.WaitOnPunctuationEnd: currentPunctuationPause = punctuationPause; break; case TokenType.Clear: textAdapter.Text = ""; break; case TokenType.SpeedStart: TryGetSingleParam(token.paramList, 0, writingSpeed, out currentWritingSpeed); break; case TokenType.SpeedEnd: currentWritingSpeed = writingSpeed; break; case TokenType.Exit: exitFlag = true; break; case TokenType.Message: if (CheckParamCount(token.paramList, 1)) { Flowchart.BroadcastFungusMessage(token.paramList[0]); } break; case TokenType.VerticalPunch: { float vintensity; float time; TryGetSingleParam(token.paramList, 0, 10.0f, out vintensity); TryGetSingleParam(token.paramList, 1, 0.5f, out time); Punch(new Vector3(0, vintensity, 0), time); } break; case TokenType.HorizontalPunch: { float hintensity; float time; TryGetSingleParam(token.paramList, 0, 10.0f, out hintensity); TryGetSingleParam(token.paramList, 1, 0.5f, out time); Punch(new Vector3(hintensity, 0, 0), time); } break; case TokenType.Punch: { float intensity; float time; TryGetSingleParam(token.paramList, 0, 10.0f, out intensity); TryGetSingleParam(token.paramList, 1, 0.5f, out time); Punch(new Vector3(intensity, intensity, 0), time); } break; case TokenType.Flash: float flashDuration; TryGetSingleParam(token.paramList, 0, 0.2f, out flashDuration); Flash(flashDuration); break; case TokenType.Audio: { AudioSource audioSource = null; if (CheckParamCount(token.paramList, 1)) { audioSource = FindAudio(token.paramList[0]); } if (audioSource != null) { audioSource.PlayOneShot(audioSource.clip); } } break; case TokenType.AudioLoop: { AudioSource audioSource = null; if (CheckParamCount(token.paramList, 1)) { audioSource = FindAudio(token.paramList[0]); } if (audioSource != null) { audioSource.Play(); audioSource.loop = true; } } break; case TokenType.AudioPause: { AudioSource audioSource = null; if (CheckParamCount(token.paramList, 1)) { audioSource = FindAudio(token.paramList[0]); } if (audioSource != null) { audioSource.Pause(); } } break; case TokenType.AudioStop: { AudioSource audioSource = null; if (CheckParamCount(token.paramList, 1)) { audioSource = FindAudio(token.paramList[0]); } if (audioSource != null) { audioSource.Stop(); } } break; } previousTokenType = token.type; if (exitFlag) { break; } } inputFlag = false; exitFlag = false; isWaitingForInput = false; isWriting = false; NotifyEnd(stopAudio); if (onComplete != null) { onComplete(); } }
protected virtual IEnumerator ProcessTokens(List <TextTagToken> tokens, bool stopAudio, Action onComplete) { // Reset control members boldActive = false; italicActive = false; colorActive = false; sizeActive = false; colorText = ""; sizeValue = 16f; currentPunctuationPause = punctuationPause; currentWritingSpeed = writingSpeed; exitFlag = false; isWriting = true; TokenType previousTokenType = TokenType.Invalid; for (int i = 0; i < tokens.Count; ++i) { // Pause between tokens if Paused is set while (Paused) { yield return(null); } var token = tokens[i]; // Notify listeners about new token WriterSignals.DoTextTagToken(this, token, i, tokens.Count); switch (token.type) { case TokenType.Words: yield return(StartCoroutine(DoWords(token.paramList, previousTokenType))); break; case TokenType.BoldStart: boldActive = true; break; case TokenType.BoldEnd: boldActive = false; break; case TokenType.ItalicStart: italicActive = true; break; case TokenType.ItalicEnd: italicActive = false; break; case TokenType.ColorStart: if (CheckParamCount(token.paramList, 1)) { colorActive = true; colorText = token.paramList[0]; } break; case TokenType.ColorEnd: colorActive = false; break; case TokenType.SizeStart: if (TryGetSingleParam(token.paramList, 0, 16f, out sizeValue)) { sizeActive = true; } break; case TokenType.SizeEnd: sizeActive = false; break; case TokenType.Wait: yield return(StartCoroutine(DoWait(token.paramList))); break; case TokenType.WaitForInputNoClear: yield return(StartCoroutine(DoWaitForInput(false))); break; case TokenType.WaitForInputAndClear: yield return(StartCoroutine(DoWaitForInput(true))); break; case TokenType.WaitOnPunctuationStart: TryGetSingleParam(token.paramList, 0, punctuationPause, out currentPunctuationPause); break; case TokenType.WaitOnPunctuationEnd: currentPunctuationPause = punctuationPause; break; case TokenType.Clear: Text = ""; break; case TokenType.SpeedStart: TryGetSingleParam(token.paramList, 0, writingSpeed, out currentWritingSpeed); break; case TokenType.SpeedEnd: currentWritingSpeed = writingSpeed; break; case TokenType.Exit: exitFlag = true; break; case TokenType.Message: if (CheckParamCount(token.paramList, 1)) { Flowchart.BroadcastFungusMessage(token.paramList[0]); } break; case TokenType.VerticalPunch: { float vintensity; float time; TryGetSingleParam(token.paramList, 0, 10.0f, out vintensity); TryGetSingleParam(token.paramList, 1, 0.5f, out time); Punch(new Vector3(0, vintensity, 0), time); } break; case TokenType.HorizontalPunch: { float hintensity; float time; TryGetSingleParam(token.paramList, 0, 10.0f, out hintensity); TryGetSingleParam(token.paramList, 1, 0.5f, out time); Punch(new Vector3(hintensity, 0, 0), time); } break; case TokenType.Punch: { float intensity; float time; TryGetSingleParam(token.paramList, 0, 10.0f, out intensity); TryGetSingleParam(token.paramList, 1, 0.5f, out time); Punch(new Vector3(intensity, intensity, 0), time); } break; case TokenType.Flash: float flashDuration; TryGetSingleParam(token.paramList, 0, 0.2f, out flashDuration); Flash(flashDuration); break; case TokenType.Audio: { AudioSource audioSource = null; if (CheckParamCount(token.paramList, 1)) { audioSource = FindAudio(token.paramList[0]); } if (audioSource != null) { audioSource.PlayOneShot(audioSource.clip); } } break; case TokenType.AudioLoop: { AudioSource audioSource = null; if (CheckParamCount(token.paramList, 1)) { audioSource = FindAudio(token.paramList[0]); } if (audioSource != null) { audioSource.Play(); audioSource.loop = true; } } break; case TokenType.AudioPause: { AudioSource audioSource = null; if (CheckParamCount(token.paramList, 1)) { audioSource = FindAudio(token.paramList[0]); } if (audioSource != null) { audioSource.Pause(); } } break; case TokenType.AudioStop: { AudioSource audioSource = null; if (CheckParamCount(token.paramList, 1)) { audioSource = FindAudio(token.paramList[0]); } if (audioSource != null) { audioSource.Stop(); } } break; } previousTokenType = token.type; if (exitFlag) { break; } } inputFlag = false; exitFlag = false; isWaitingForInput = false; isWriting = false; NotifyEnd(stopAudio); if (onComplete != null) { onComplete(); } }