Esempio n. 1
0
        /// <summary>
        /// Internal coroutine used for repeated play without end
        /// </summary>
        /// <param name="position"></param>
        /// <param name="feedbacksIntensity"></param>
        /// <returns></returns>
        protected virtual IEnumerator InfinitePlay(Vector3 position, float feedbacksIntensity = 1.0f)
        {
            while (true)
            {
                _lastPlayTimestamp = FeedbackTime;
                if (Timing.Sequence == null)
                {
                    CustomPlayFeedback(position, feedbacksIntensity);
                    if (Timing.TimescaleMode == TimescaleModes.Scaled)
                    {
                        yield return(MMFeedbacksCoroutine.WaitFor(Timing.DelayBetweenRepeats));
                    }
                    else
                    {
                        yield return(MMFeedbacksCoroutine.WaitForUnscaled(Timing.DelayBetweenRepeats));
                    }
                }
                else
                {
                    _sequenceCoroutine = StartCoroutine(SequenceCoroutine(position, feedbacksIntensity));

                    float delay = ApplyTimeMultiplier(Timing.DelayBetweenRepeats) + Timing.Sequence.Length;
                    if (Timing.TimescaleMode == TimescaleModes.Scaled)
                    {
                        yield return(MMFeedbacksCoroutine.WaitFor(delay));
                    }
                    else
                    {
                        yield return(MMFeedbacksCoroutine.WaitForUnscaled(delay));
                    }
                }
            }
        }
Esempio n. 2
0
        protected virtual IEnumerator HandleInitialDelayCo(Vector3 position, float feedbacksIntensity, bool forceRevert = false)
        {
            IsPlaying = true;
            yield return(MMFeedbacksCoroutine.WaitFor(InitialDelay));

            PreparePlay(position, feedbacksIntensity, forceRevert);
        }
Esempio n. 3
0
 /// <summary>
 /// An IEnumerator used to wait for the duration of the pause, on scaled or unscaled time
 /// </summary>
 /// <returns></returns>
 protected virtual IEnumerator PauseWait()
 {
     if (Timing.TimescaleMode == TimescaleModes.Scaled)
     {
         return(MMFeedbacksCoroutine.WaitFor(PauseDuration));
     }
     else
     {
         return(MMFeedbacksCoroutine.WaitForUnscaled(PauseDuration));
     }
 }
        /// <summary>
        /// Reveals characters one at a time
        /// </summary>
        /// <returns></returns>
        protected virtual IEnumerator RevealCharacters()
        {
            float startTime         = (Timing.TimescaleMode == TimescaleModes.Scaled) ? Time.time : Time.unscaledTime;
            int   totalCharacters   = _richTextLength;
            int   visibleCharacters = 0;
            float lastCharAt        = 0f;

            IsPlaying = true;
            while (visibleCharacters <= totalCharacters)
            {
                float deltaTime = (Timing.TimescaleMode == TimescaleModes.Scaled) ? Time.deltaTime : Time.unscaledDeltaTime;
                float time      = (Timing.TimescaleMode == TimescaleModes.Scaled) ? Time.time : Time.unscaledTime;

                if (time - lastCharAt < IntervalBetweenReveals)
                {
                    yield return(null);
                }

                TargetTMPText.maxVisibleCharacters = visibleCharacters;
                visibleCharacters++;
                lastCharAt = time;

                // we adjust our delay

                float delay = 0f;

                if (DurationMode == DurationModes.Interval)
                {
                    _delay = Mathf.Max(IntervalBetweenReveals, deltaTime);
                    delay  = _delay - deltaTime;
                }
                else
                {
                    int   remainingCharacters = totalCharacters - visibleCharacters;
                    float elapsedTime         = time - startTime;
                    if (remainingCharacters != 0)
                    {
                        _delay = (RevealDuration - elapsedTime) / remainingCharacters;
                    }
                    delay = _delay - deltaTime;
                }

                if (Timing.TimescaleMode == TimescaleModes.Scaled)
                {
                    yield return(MMFeedbacksCoroutine.WaitFor(delay));
                }
                else
                {
                    yield return(MMFeedbacksCoroutine.WaitForUnscaled(delay));
                }
            }
            TargetTMPText.maxVisibleCharacters = _richTextLength;
            IsPlaying = false;
        }
Esempio n. 5
0
 /// <summary>
 /// An internal coroutine delaying the initial play of the feedback
 /// </summary>
 /// <param name="position"></param>
 /// <param name="feedbacksIntensity"></param>
 /// <returns></returns>
 protected virtual IEnumerator PlayCoroutine(Vector3 position, float feedbacksIntensity = 1.0f)
 {
     if (Timing.TimescaleMode == TimescaleModes.Scaled)
     {
         yield return(MMFeedbacksCoroutine.WaitFor(Timing.InitialDelay));
     }
     else
     {
         yield return(MMFeedbacksCoroutine.WaitForUnscaled(Timing.InitialDelay));
     }
     _lastPlayTimestamp = FeedbackTime;
     RegularPlay(position, feedbacksIntensity);
 }
Esempio n. 6
0
        /// <summary>
        /// Reveals words one at a time
        /// </summary>
        /// <returns></returns>
        protected virtual IEnumerator RevealWords()
        {
            int totalWords   = TargetTMPText.textInfo.wordCount;
            int visibleWords = 0;

            while (visibleWords <= totalWords)
            {
                TargetTMPText.maxVisibleWords = visibleWords;
                visibleWords++;

                yield return(MMFeedbacksCoroutine.WaitFor(_delay));
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Reveals characters one at a time
        /// </summary>
        /// <returns></returns>
        protected virtual IEnumerator RevealCharacters()
        {
            int totalCharacters   = TargetTMPText.textInfo.characterCount;
            int visibleCharacters = 0;

            while (visibleCharacters <= totalCharacters)
            {
                TargetTMPText.maxVisibleCharacters = visibleCharacters;
                visibleCharacters++;

                yield return(MMFeedbacksCoroutine.WaitFor(_delay));
            }
        }
Esempio n. 8
0
        public virtual IEnumerator Flicker(Renderer renderer, int materialIndex, Color initialColor, Color flickerColor, float flickerSpeed, float flickerDuration)
        {
            if (renderer == null)
            {
                yield break;
            }

            if (!_propertiesFound[materialIndex])
            {
                yield break;
            }

            if (initialColor == flickerColor)
            {
                yield break;
            }

            float flickerStop = FeedbackTime + flickerDuration;

            IsPlaying = true;

            while (FeedbackTime < flickerStop)
            {
                SetColor(materialIndex, flickerColor);
                if (Timing.TimescaleMode == TimescaleModes.Scaled)
                {
                    yield return(MMFeedbacksCoroutine.WaitFor(flickerSpeed));
                }
                else
                {
                    yield return(MMFeedbacksCoroutine.WaitForUnscaled(flickerSpeed));
                }
                SetColor(materialIndex, initialColor);
                if (Timing.TimescaleMode == TimescaleModes.Scaled)
                {
                    yield return(MMFeedbacksCoroutine.WaitFor(flickerSpeed));
                }
                else
                {
                    yield return(MMFeedbacksCoroutine.WaitForUnscaled(flickerSpeed));
                }
            }

            SetColor(materialIndex, initialColor);
            IsPlaying = false;
        }
Esempio n. 9
0
        /// <summary>
        /// Reveals words one at a time
        /// </summary>
        /// <returns></returns>
        protected virtual IEnumerator RevealWords()
        {
            int totalWords   = TargetTMPText.textInfo.wordCount;
            int visibleWords = 0;

            while (visibleWords <= totalWords)
            {
                TargetTMPText.maxVisibleWords = visibleWords;
                visibleWords++;

                if (Timing.TimescaleMode == TimescaleModes.Scaled)
                {
                    yield return(MMFeedbacksCoroutine.WaitFor(_delay));
                }
                else
                {
                    yield return(MMFeedbacksCoroutine.WaitForUnscaled(_delay));
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Reveals characters one at a time
        /// </summary>
        /// <returns></returns>
        protected virtual IEnumerator RevealCharacters()
        {
            int totalCharacters   = TargetTMPText.text.Length;
            int visibleCharacters = 0;

            while (visibleCharacters <= totalCharacters)
            {
                TargetTMPText.maxVisibleCharacters = visibleCharacters;
                visibleCharacters++;

                if (Timing.TimescaleMode == TimescaleModes.Scaled)
                {
                    yield return(MMFeedbacksCoroutine.WaitFor(_delay));
                }
                else
                {
                    yield return(MMFeedbacksCoroutine.WaitForUnscaled(_delay));
                }
            }
        }
        /// <summary>
        /// Reveals lines one at a time
        /// </summary>
        /// <returns></returns>
        protected virtual IEnumerator RevealLines()
        {
            int totalLines   = TargetTMPText.textInfo.lineCount;
            int visibleLines = 0;

            IsPlaying = true;
            while (visibleLines <= totalLines)
            {
                TargetTMPText.maxVisibleLines = visibleLines;
                visibleLines++;

                if (Timing.TimescaleMode == TimescaleModes.Scaled)
                {
                    yield return(MMFeedbacksCoroutine.WaitFor(_delay));
                }
                else
                {
                    yield return(MMFeedbacksCoroutine.WaitForUnscaled(_delay));
                }
            }
            IsPlaying = false;
        }
Esempio n. 12
0
        /// <summary>
        /// An internal method used to play feedbacks, shouldn't be called externally
        /// </summary>
        /// <param name="position"></param>
        /// <param name="feedbacksIntensity"></param>
        protected virtual IEnumerator PlayFeedbacksInternal(Vector3 position, float feedbacksIntensity, bool forceRevert = false)
        {
            if (IsPlaying && !CanPlayWhileAlreadyPlaying)
            {
                yield break;
            }

            if (ShouldRevertOnNextPlay)
            {
                Revert();
                ShouldRevertOnNextPlay = false;
            }

            if (forceRevert)
            {
                Direction = (Direction == Directions.BottomToTop) ? Directions.TopToBottom : Directions.BottomToTop;
            }

            // if we have a cooldown we prevent execution if needed
            if (CooldownDuration > 0f)
            {
                if (Time.unscaledTime - _lastStartAt < CooldownDuration)
                {
                    yield break;
                }
            }

            if (InitialDelay > 0f)
            {
                yield return(MMFeedbacksCoroutine.WaitFor(InitialDelay));
            }

            // if this MMFeedbacks is disabled in any way, we stop and don't play
            if (!this.isActiveAndEnabled)
            {
                yield break;
            }

            // if all MMFeedbacks are disabled globally, we stop and don't play
            if (!GlobalMMFeedbacksActive)
            {
                yield break;
            }

            Events.TriggerOnPlay(this);

            _startTime   = Time.unscaledTime;
            _holdingMax  = 0f;
            _lastStartAt = _startTime;

            ResetFeedbacks();

            // test if a pause or holding pause is found
            bool pauseFound = false;

            for (int i = 0; i < Feedbacks.Count; i++)
            {
                if ((Feedbacks[i].Pause != null) && (Feedbacks[i].Active) && (Feedbacks[i].ShouldPlayInThisSequenceDirection))
                {
                    pauseFound = true;
                }
                if ((Feedbacks[i].HoldingPause == true) && (Feedbacks[i].Active) && (Feedbacks[i].ShouldPlayInThisSequenceDirection))
                {
                    pauseFound = true;
                }
            }

            if (!pauseFound)
            {
                // if no pause was found, we just play all feedbacks at once
                IsPlaying = true;
                for (int i = 0; i < Feedbacks.Count; i++)
                {
                    if (FeedbackCanPlay(Feedbacks[i]))
                    {
                        Feedbacks[i].Play(position, feedbacksIntensity);
                    }
                }

                float startTime = Time.unscaledTime;
                while (Time.unscaledTime - startTime < TotalDuration - InitialDelay)
                {
                    yield return(null);
                }

                IsPlaying = false;
                Events.TriggerOnComplete(this);
                ApplyAutoRevert();
            }
            else
            {
                // if at least one pause was found
                StartCoroutine(PausedFeedbacksCo(position, feedbacksIntensity));
            }

            while (IsPlaying)
            {
                yield return(null);
            }
        }