Example #1
0
        private void ProcessRPGMakerCodes()
        {
            rpgMakerTokens.Clear();
            var source = textComponent.text;
            var result = string.Empty;

            if (!source.Contains("\\"))
            {
                return;
            }
            source = Tools.StripTextMeshProTags(source);
            int safeguard = 0;

            while (!string.IsNullOrEmpty(source) && safeguard < 9999)
            {
                safeguard++;
                RPGMakerTokenType token;
                if (PeelRPGMakerTokenFromFront(ref source, out token))
                {
                    int i = result.Length;
                    if (!rpgMakerTokens.ContainsKey(i))
                    {
                        rpgMakerTokens.Add(i, new List <RPGMakerTokenType>());
                    }
                    rpgMakerTokens[i].Add(token);
                }
                else
                {
                    result += source[0];
                    source  = source.Remove(0, 1);
                }
            }
            textComponent.text = Regex.Replace(textComponent.text, @"\\[\.\,\^\<\>]", string.Empty);
        }
Example #2
0
        /// <summary>
        /// Sets the content of the panel. Assumes the panel is already open.
        /// </summary>
        public virtual void SetContent(Subtitle subtitle)
        {
            if (subtitle == null)
            {
                return;
            }
            currentSubtitle = subtitle;
            CheckSubtitleAnimator(subtitle);
            if (!onlyShowNPCPortraits || subtitle.speakerInfo.isNPC)
            {
                if (portraitImage != null)
                {
                    var sprite = subtitle.GetSpeakerPortrait();
                    portraitImage.sprite = sprite;
                    Tools.SetGameObjectActive(portraitImage, sprite != null);
                }
                portraitActorName = subtitle.speakerInfo.nameInDatabase;
                portraitName.text = subtitle.speakerInfo.Name;
                UITools.SendTextChangeMessage(portraitName);
            }
            TypewriterUtility.StopTyping(subtitleText);
            var previousText  = accumulateText ? m_accumulatedText : string.Empty;
            var previousChars = accumulateText ? UITools.StripRPGMakerCodes(Tools.StripTextMeshProTags(Tools.StripRichTextCodes(previousText))).Length : 0;

            SetFormattedText(subtitleText, previousText, subtitle.formattedText);
            if (accumulateText)
            {
                m_accumulatedText = subtitleText.text + "\n";
            }
            if (delayTypewriterUntilOpen && !hasFocus)
            {
                StartCoroutine(StartTypingWhenFocused(subtitleText, subtitleText.text, previousChars));
            }
            else
            {
                TypewriterUtility.StartTyping(subtitleText, subtitleText.text, previousChars);
            }
            frameLastSetContent = Time.frameCount;
        }
Example #3
0
        /// <summary>
        /// Plays the typewriter effect.
        /// </summary>
        public IEnumerator Play(int fromIndex)
        {
            if ((textComponent != null) && (charactersPerSecond > 0))
            {
                if (waitOneFrameBeforeStarting)
                {
                    yield return(null);
                }
                fromIndex = StripRPGMakerCodes(Tools.StripTextMeshProTags(textComponent.text)).Substring(0, fromIndex).Length;
                ProcessRPGMakerCodes();
                if (runtimeAudioSource != null)
                {
                    runtimeAudioSource.clip = audioClip;
                }
                onBegin.Invoke();
                paused = false;
                float delay    = 1 / charactersPerSecond;
                float lastTime = DialogueTime.time;
                float elapsed  = fromIndex / charactersPerSecond;
                textComponent.maxVisibleCharacters = fromIndex;
                textComponent.ForceMeshUpdate();
                yield return(null);

                textComponent.maxVisibleCharacters = fromIndex;
                textComponent.ForceMeshUpdate();
                TMPro.TMP_TextInfo textInfo = textComponent.textInfo;
                int totalVisibleCharacters  = textInfo.characterCount; // Get # of Visible Character in text object
                charactersTyped = fromIndex;
                int skippedCharacters = 0;
                while (charactersTyped < totalVisibleCharacters)
                {
                    if (!paused)
                    {
                        var deltaTime = DialogueTime.time - lastTime;
                        elapsed += deltaTime;
                        var goal = (elapsed * charactersPerSecond) - skippedCharacters;
                        while (charactersTyped < goal)
                        {
                            if (rpgMakerTokens.ContainsKey(charactersTyped))
                            {
                                var tokens = rpgMakerTokens[charactersTyped];
                                for (int i = 0; i < tokens.Count; i++)
                                {
                                    var token = tokens[i];
                                    switch (token)
                                    {
                                    case RPGMakerTokenType.QuarterPause:
                                        yield return(DialogueTime.WaitForSeconds(quarterPauseDuration));

                                        break;

                                    case RPGMakerTokenType.FullPause:
                                        yield return(DialogueTime.WaitForSeconds(fullPauseDuration));

                                        break;

                                    case RPGMakerTokenType.SkipToEnd:
                                        charactersTyped = totalVisibleCharacters - 1;
                                        break;

                                    case RPGMakerTokenType.InstantOpen:
                                        var close = false;
                                        while (!close && charactersTyped < totalVisibleCharacters)
                                        {
                                            charactersTyped++;
                                            skippedCharacters++;
                                            if (rpgMakerTokens.ContainsKey(charactersTyped) && rpgMakerTokens[charactersTyped].Contains(RPGMakerTokenType.InstantClose))
                                            {
                                                close = true;
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                            var typedCharacter = (0 <= charactersTyped && charactersTyped < textComponent.text.Length) ? textComponent.text[charactersTyped] : ' ';
                            if (charactersTyped < totalVisibleCharacters && !IsSilentCharacter(typedCharacter))
                            {
                                PlayCharacterAudio();
                            }
                            onCharacter.Invoke();
                            charactersTyped++;
                            textComponent.maxVisibleCharacters = charactersTyped;
                            if (IsFullPauseCharacter(typedCharacter))
                            {
                                yield return(DialogueTime.WaitForSeconds(fullPauseDuration));
                            }
                            else if (IsQuarterPauseCharacter(typedCharacter))
                            {
                                yield return(DialogueTime.WaitForSeconds(quarterPauseDuration));
                            }
                        }
                    }
                    textComponent.maxVisibleCharacters = charactersTyped;
                    HandleAutoScroll();
                    //---Uncomment the line below to debug:
                    //Debug.Log(textComponent.text.Substring(0, charactersTyped).Replace("<", "[").Replace(">", "]") + " (typed=" + charactersTyped + ")");
                    lastTime = DialogueTime.time;
                    var delayTime      = DialogueTime.time + delay;
                    int delaySafeguard = 0;
                    while (DialogueTime.time < delayTime && delaySafeguard < 999)
                    {
                        delaySafeguard++;
                        yield return(null);
                    }
                }
            }
            Stop();
        }