Exemple #1
0
        /// <summary>
        /// On Update, we move our value based on the defined settings
        /// </summary>
        protected virtual void Update()
        {
            _targetObjectLastFrame    = TargetObject;
            _targetAttributeLastFrame = TargetAttribute;

            if ((TargetObject == null) || (TargetAttribute == null) || (!_attributeFound))
            {
                return;
            }

            switch (ControlMode)
            {
            case ControlModes.PingPong:

                if (GetTime() - _lastPingPongPauseAt < PingPongPauseDuration)
                {
                    return;
                }
                PingPong += GetDeltaTime() * _pingPongDirection;

                if (PingPong < 0f)
                {
                    PingPong             = 0f;
                    _pingPongDirection   = -_pingPongDirection;
                    _lastPingPongPauseAt = GetTime();
                }

                if (PingPong > Duration)
                {
                    PingPong             = Duration;
                    _pingPongDirection   = -_pingPongDirection;
                    _lastPingPongPauseAt = GetTime();
                }
                CurrentValue           = MMTween.Tween(PingPong, 0f, Duration, MinValue, MaxValue, Curve);
                CurrentValueNormalized = MMMaths.Remap(CurrentValue, MinValue, MaxValue, 0f, 1f);
                break;

            case ControlModes.Random:
                _elapsedTime          += GetDeltaTime();
                CurrentValueNormalized = Mathf.PerlinNoise(_randomFrequency * _elapsedTime, _randomShift);
                if (RemapNoiseValues)
                {
                    CurrentValue = CurrentValueNormalized;
                    CurrentValue = MMMaths.Remap(CurrentValue, 0f, 1f, RemapNoiseZero, RemapNoiseOne);
                }
                else
                {
                    CurrentValue = (CurrentValueNormalized * 2.0f - 1.0f) * _randomAmplitude;
                }
                break;

            case ControlModes.OneTime:
                if (!_shaking)
                {
                    return;
                }
                _remappedTimeSinceStart = MMMaths.Remap(Time.time - _shakeStartTimestamp, 0f, OneTimeDuration, 0f, 1f);
                CurrentValueNormalized  = OneTimeCurve.Evaluate(_remappedTimeSinceStart);
                CurrentValue            = MMMaths.Remap(CurrentValueNormalized, 0f, 1f, OneTimeRemapMin, OneTimeRemapMax);
                CurrentValue           *= OneTimeAmplitude;
                break;

            case ControlModes.AudioAnalyzer:
                if (AudioAnalyzerMode == AudioAnalyzerModes.Beat)
                {
                    CurrentValue = AudioAnalyzer.Beats[BeatID].CurrentValue * AudioAnalyzerMultiplier;
                }
                else
                {
                    CurrentValue = AudioAnalyzer.NormalizedBufferedBandLevels[NormalizedLevelID] * AudioAnalyzerMultiplier;
                }
                CurrentValueNormalized = Mathf.Clamp(AudioAnalyzer.Beats[BeatID].CurrentValue, 0f, 1f);
                break;

            case ControlModes.Driven:
                CurrentValue           = DrivenLevel;
                CurrentValueNormalized = Mathf.Clamp(CurrentValue, 0f, 1f);
                break;

            case ControlModes.ToDestination:
                if (!_shaking)
                {
                    return;
                }
                _remappedTimeSinceStart = MMMaths.Remap(Time.time - _shakeStartTimestamp, 0f, ToDestinationDuration, 0f, 1f);
                float time = ToDestinationCurve.Evaluate(_remappedTimeSinceStart);
                CurrentValue           = Mathf.LerpUnclamped(_initialValue, ToDestinationValue, time);
                CurrentValueNormalized = MMMaths.Remap(CurrentValue, _initialValue, ToDestinationValue, 0f, 1f);
                break;
            }


            if (AddToInitialValue)
            {
                CurrentValue += InitialValue;
            }

            if (ControlMode == ControlModes.OneTime)
            {
                if (_shaking && (Time.time - _shakeStartTimestamp > OneTimeDuration))
                {
                    _shaking = false;
                    if (RevertToInitialValueAfterEnd)
                    {
                        CurrentValue = InitialValue;
                        TargetAttribute.SetValue(CurrentValue);
                    }
                    else
                    {
                        CurrentValue  = OneTimeCurve.Evaluate(1f);
                        CurrentValue  = MMMaths.Remap(CurrentValue, 0f, 1f, OneTimeRemapMin, OneTimeRemapMax);
                        CurrentValue *= OneTimeAmplitude;
                        TargetAttribute.SetValue(CurrentValue);
                    }
                    if (DisableAfterOneTime)
                    {
                        this.enabled = false;
                    }
                    if (DisableGameObjectAfterOneTime)
                    {
                        this.gameObject.SetActive(false);
                    }
                    return;
                }
            }

            if (ControlMode == ControlModes.ToDestination)
            {
                if (_shaking && (Time.time - _shakeStartTimestamp > ToDestinationDuration))
                {
                    _shaking = false;
                    if (RevertToInitialValueAfterEnd)
                    {
                        CurrentValue = InitialValue;
                    }
                    else
                    {
                        CurrentValue = ToDestinationValue;
                    }
                    TargetAttribute.SetValue(CurrentValue);

                    if (DisableAfterOneTime)
                    {
                        this.enabled = false;
                    }
                    if (DisableGameObjectAfterOneTime)
                    {
                        this.gameObject.SetActive(false);
                    }
                    return;
                }
            }

            TargetAttribute.SetValue(CurrentValue);
        }
Exemple #2
0
        /// <summary>
        /// On Update, we move our value based on the defined settings
        /// </summary>
        protected virtual void Update()
        {
            if ((TargetObject == null) || (TargetAttribute == null) || (!Active) || (!_attributeFound))
            {
                return;
            }

            switch (ControlMode)
            {
            case ControlModes.PingPong:

                if (GetTime() - _lastPingPongPauseAt < PingPongPauseDuration)
                {
                    return;
                }
                PingPong += GetDeltaTime() * _pingPongDirection;

                if (PingPong < 0f)
                {
                    PingPong             = 0f;
                    _pingPongDirection   = -_pingPongDirection;
                    _lastPingPongPauseAt = GetTime();
                }

                if (PingPong > Duration)
                {
                    PingPong             = Duration;
                    _pingPongDirection   = -_pingPongDirection;
                    _lastPingPongPauseAt = GetTime();
                }


                CurrentValue = MMTween.Tween(PingPong, 0f, Duration, MinValue, MaxValue, Curve);
                break;

            case ControlModes.Random:
                _elapsedTime += GetDeltaTime();
                CurrentValue  = (Mathf.PerlinNoise(_randomFrequency * _elapsedTime, _randomShift) * 2.0f - 1.0f) * _randomAmplitude;
                break;

            case ControlModes.OneTime:
                if (!_oneTimeShaking)
                {
                    return;
                }
                _remappedTimeSinceStart = MMMaths.Remap(Time.time - _oneTimeStartedTimestamp, 0f, OneTimeDuration, 0f, 1f);
                CurrentValue            = OneTimeCurve.Evaluate(_remappedTimeSinceStart) * OneTimeAmplitude;
                if (AddToInitialValue)
                {
                    CurrentValue += InitialValue;
                }
                break;

            case ControlModes.AudioAnalyzer:
                CurrentValue = AudioAnalyzer.Beats[BeatID].CurrentValue * AudioAnalyzerMultiplier;
                break;
            }


            if (AddToInitialValue)
            {
                CurrentValue += InitialValue;
            }

            if (_oneTimeShaking && (Time.time - _oneTimeStartedTimestamp > OneTimeDuration))
            {
                _oneTimeShaking = false;
                CurrentValue    = InitialValue;
            }

            TargetAttribute.SetValue(CurrentValue);
        }