示例#1
0
        public IEnumerator Text(string richText)
        {
            // Announce new ID is typing
            int myTypingId = ++typingId;

            startTyping.Invoke();
            TextComponent.text = string.Empty;

            string plainText = TextUtil.StripTags(richText);

            for (int visibleLength = 1; visibleLength <= plainText.Length; visibleLength++)
            {
                TypingState typingState = new TypingState(richText, visibleLength, plainText);
                float       delay       = GetDelay(typingState) * DelayScale;

                // Finish typing (with cleanup) if delay is 0
                if (delay == 0)
                {
                    break;
                }
                else
                {
                    yield return(YieldUtil.WaitForSecondsScaled(delay, scaledTime));
                }

                // Stop typing if anyone else has started
                if (typingId != myTypingId)
                {
                    yield break;
                }

                TextComponent.text = TextUtil.InsertTagRichText(richText, visibleLength, plainText.Length, "<color=#fff0>", "</color>");
                characterTyped.Invoke(typingState);
            }

            TextComponent.text = richText;
            typingId           = 0;
            finishTyping.Invoke();
        }
示例#2
0
 private float GetDelay(TypingState typingState)
 {
     return(typingState.CurrentWord.Contains(typingState.CursorPos - 1)
         ? characterDelay : whitespaceDelay);
 }