public virtual IEnumerator OtherPlay(int fromIndex)
        {
            int count = 0;

            while (true)
            {
                maxVisibleCharacters = count;
                count++;
                yield return(DialogueTime.WaitForSeconds(quarterPauseDuration));
            }
        }
Example #2
0
 private IEnumerator DisableAfterAnimation(UnityEngine.UI.Graphic panel)
 {
     isHiding = true;
     if (animator != null)
     {
         const float maxWaitDuration = 10;
         float       timeout         = Time.realtimeSinceStartup + maxWaitDuration;
         var         oldHashId       = UITools.GetAnimatorNameHash(animator.GetCurrentAnimatorStateInfo(0));
         while ((UITools.GetAnimatorNameHash(animator.GetCurrentAnimatorStateInfo(0)) == oldHashId) && (Time.realtimeSinceStartup < timeout))
         {
             yield return(null);
         }
         yield return(DialogueManager.Instance.StartCoroutine(DialogueTime.WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length)));
     }
     isHiding = false;
     if (panel != null)
     {
         Tools.SetGameObjectActive(panel, false);
     }
 }
Example #3
0
        private IEnumerator MonitorDistance(Transform actor)
        {
            if (actor != null)
            {
                Transform myTransform = transform;
                while (true)
                {
                    yield return(StartCoroutine(DialogueTime.WaitForSeconds(monitorFrequency))); // new WaitForSeconds(monitorFrequency);

                    if (Vector3.Distance(myTransform.position, actor.position) > maxDistance)
                    {
                        if (DialogueDebug.logInfo)
                        {
                            Debug.Log(string.Format("{0}: Stopping conversation. Exceeded max distance {1} between {2} and {3}", new System.Object[] { DialogueDebug.Prefix, maxDistance, name, actor.name }));
                        }
                        DialogueManager.StopConversation();
                        yield break;
                    }
                }
            }
        }
        /// <summary>
        /// Plays the typewriter effect.
        /// </summary>
        public virtual IEnumerator Play(int fromIndex)
        {
            if ((textComponent != null) && (charactersPerSecond > 0))
            {
                if (waitOneFrameBeforeStarting)
                {
                    yield return(null);
                }
                fromIndex = StripRPGMakerCodes(Tools.StripTags(textComponent.text.Substring(0, fromIndex))).Length;
                ProcessRPGMakerCodes();
                ProcessTags();
                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;
                var parsedText             = textComponent.GetParsedText();
                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 < parsedText.Length) ? parsedText[charactersTyped] : ' ';
                            if (charactersTyped < totalVisibleCharacters && !IsSilentCharacter(typedCharacter))
                            {
                                PlayCharacterAudio(typedCharacter);
                            }
                            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();
        }