Exemple #1
0
        /// <summary>
        /// Plays the typewriter effect.
        /// </summary>
        public override IEnumerator Play()
        {
            GUILabel control = GetComponent <GUILabel>();

            if (control == null)
            {
                yield break;
            }
            IsPlaying             = true;
            control.currentLength = 0;
            while ((control.currentLength + 1) < control.text.Length)
            {
                float delay = 1 / charactersPerSecond;
                if (!DialogueTime.isPaused)
                {
                    if (audioClip != null && control.currentLength > 0)
                    {
                        control.PlaySound(audioClip);
                    }
                    AdvanceOneCharacter(control);
                    // The code below adds extra delay for punctuation, but I'm not sure I like it:
                    // char c = control.text[control.currentLength];
                    // if (c == '.' || c == '\n' || c == '!' || c == '?') delay *= 4f;
                }

                yield return(StartCoroutine(DialogueTime.WaitForSeconds(delay))); // new WaitForSeconds(delay);
            }
            control.currentLength = control.text.Length;
            control.ResetClosureTags();
            IsPlaying = false;
        }
        /// <summary>
        /// Plays the flash effect.
        /// </summary>
        public override IEnumerator Play()
        {
            control = GetComponent <GUIControl>();
            if (control == null)
            {
                yield break;
            }
            control.visible = true;
            while (true)
            {
                yield return(StartCoroutine(DialogueTime.WaitForSeconds(interval))); // new WaitForSeconds(interval);

                control.visible = !control.visible;
            }
        }
Exemple #3
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);
     }
 }
        /// <summary>
        /// Monitors the animator state. Stops the sequence when the state is done,
        /// or after maXDurationToWaitForStateStart (1 second) if it never enters
        /// that state.
        /// </summary>
        /// <param name="animator">Animator.</param>
        /// <param name="stateName">State name.</param>
        private IEnumerator MonitorState(Animator animator, string stateName)
        {
            // Wait to enter the state:
            float             maxStartTime = DialogueTime.time + maxDurationToWaitForStateStart;
            AnimatorStateInfo animatorStateInfo;
            bool isInState = CheckIsInState(animator, stateName, out animatorStateInfo);

            while (!isInState && (DialogueTime.time < maxStartTime))
            {
                yield return(null);

                isInState = CheckIsInState(animator, stateName, out animatorStateInfo);
            }

            // Wait for state to end, then stop:
            if (isInState)
            {
                yield return(StartCoroutine(DialogueTime.WaitForSeconds(animatorStateInfo.length))); //new WaitForSeconds(animatorStateInfo.length);
            }
            Stop();
        }
Exemple #5
0
        /// <summary>
        /// Plays the fade effect.
        /// </summary>
        public override IEnumerator Play()
        {
            control = GetComponent <GUIVisibleControl>();
            if (control == null)
            {
                yield break;
            }

            // Fade in:
            float startTime = DialogueTime.time;
            float endTime   = startTime + fadeInDuration;

            while (DialogueTime.time < endTime)
            {
                float elapsed = DialogueTime.time - startTime;
                control.Alpha = elapsed / fadeInDuration;
                yield return(null);
            }
            control.Alpha = 1;

            // If no fade out, exit:
            if (Tools.ApproximatelyZero(fadeOutDuration))
            {
                yield break;
            }

            // Visible duration:
            yield return(StartCoroutine(DialogueTime.WaitForSeconds(duration))); // new WaitForSeconds(duration);

            // Fade out:
            startTime = DialogueTime.time;
            endTime   = startTime + fadeOutDuration;
            while (DialogueTime.time < endTime)
            {
                float elapsed = DialogueTime.time - startTime;
                control.Alpha = 1 - (elapsed / fadeOutDuration);
                yield return(null);
            }
            control.Alpha = 0;
        }