コード例 #1
0
        /// <summary>
        /// When getting a freeze frame event we stop the time
        /// </summary>
        /// <param name="freezeFrameEvent">Freeze frame event.</param>
        public void OnMMEvent(MMFreezeFrameEvent freezeFrameEvent)
        {
            _frozenTimeLeft = freezeFrameEvent.FreezeDuration;

            TimeScaleProperties properties = new TimeScaleProperties();

            properties.Duration  = freezeFrameEvent.FreezeDuration;
            properties.Lerp      = false;
            properties.LerpSpeed = 0f;
            properties.TimeScale = 0f;

            SetTimeScale(properties);
        }
コード例 #2
0
        /// <summary>
        /// On Update, applies the timescale and resets it if needed
        /// </summary>
        protected virtual void Update()
        {
            // if we have things in our stack, we handle them, otherwise we reset to the normal timescale
            if (_timeScaleProperties.Count > 0)
            {
                _currentProperty = _timeScaleProperties.Peek();

                TargetTimeScale            = _currentProperty.TimeScale;
                LerpSpeed                  = _currentProperty.LerpSpeed;
                LerpTimescale              = _currentProperty.Lerp;
                _currentProperty.Duration -= Time.unscaledDeltaTime;

                _timeScaleProperties.Pop();
                _timeScaleProperties.Push(_currentProperty);

                if (_currentProperty.Duration <= 0f && !_currentProperty.Infinite)
                {
                    Unfreeze();
                }
            }
            else
            {
                TargetTimeScale = NormalTimescale;
            }

            // we apply our timescale
            if (LerpTimescale)
            {
                Time.timeScale = Mathf.Lerp(Time.timeScale, TargetTimeScale, Time.unscaledDeltaTime * LerpSpeed);
            }
            else
            {
                Time.timeScale = TargetTimeScale;
            }

            CurrentTimeScale = Time.timeScale;
        }
コード例 #3
0
 /// <summary>
 /// Sets the time scale for the specified properties (duration, time scale, lerp or not, and lerp speed)
 /// </summary>
 /// <param name="timeScaleProperties">Time scale properties.</param>
 protected virtual void SetTimeScale(TimeScaleProperties timeScaleProperties)
 {
     _timeScaleProperties.Push(timeScaleProperties);
 }