Exemplo n.º 1
0
 public EyeDialationAnimation(float startValue, float targetValue, float duration, Func <float, float> easing = null)
 {
     _startValue  = startValue;
     _targetValue = targetValue;
     _easing      = easing ?? ((p) => Easings.Linear(p));
     _duration    = duration;
     _currentTime = 0;
 }
Exemplo n.º 2
0
        private void Update()
        {
            if (!_initCompleted)
            {
                return;
            }
            if (SuperController.singleton.freezeAnimation)
            {
                return;
            }
#if LFE_DEBUG
            if (Input.GetKey("up"))
            {
                CameraTarget.centerTarget.targetCamera.enabled = false;
                _detector.Detector.enabled = true;
            }
            else
            {
                CameraTarget.centerTarget.targetCamera.enabled = true;
                _detector.Detector.enabled = true;
            }
#endif

            try
            {
                _brightnessChangeCountdown -= Time.deltaTime;
                // run the scheduled animation
                if (_currentAnimation != null)
                {
                    _pupilMorph.morphValueAdjustLimits = Math.Clamp(_currentAnimation.Update(), -1.5f, 2.0f);
                    if (_currentAnimation.IsFinished)
                    {
                        _currentAnimation = null;

                        // schedule a new idle
                        _idleCountDown = UnityEngine.Random.Range(0.01f, Math.Max(IdleMaxDelayStorable.val, 0.01f));
                    }
                }

                var brightness   = CalculateBrightness();
                var currentValue = _pupilMorph.morphValue;
                var targetValue  = BrightnessToMorphValue(brightness);
                var duration     = 0f;

                if (_lastBrightness == brightness)
                {
                    // maybe schedule an idle animation - but do not interrupt an animation in progress just for idle
                    if (_currentAnimation == null && _idleCountDown < 0)
                    {
                        duration    = Math.Max(IdleAdjustSpeedStorable.val, 0.01f);
                        _idleSign   = _idleSign * -1;
                        targetValue = targetValue + (_idleSign * UnityEngine.Random.Range(0.01f, IdleStrengthStorable.val));

                        _currentAnimation = new EyeDialationAnimation(currentValue, targetValue, duration, (p) => Easings.BackEaseOut(p));
                    }
                    else
                    {
                        _idleCountDown -= Time.deltaTime;
                    }
                }
                else
                {
                    if (_brightnessChangeCountdown <= 0)
                    {
                        // schedule brightness adjustment animation - override any currently running animation for this one. light always wins
                        duration = targetValue > currentValue
                            ? DarkAdjustSpeedStorable.val
                            : LightAdjustSpeedStorable.val;
                        _currentAnimation          = new EyeDialationAnimation(currentValue, targetValue, duration, (p) => Easings.ElasticEaseOut(p));
                        _brightnessChangeCountdown = _brightnessChangeThrottle;
                    }
                }

                _lastBrightness = brightness;
            }
            catch (Exception ex)
            {
                SuperController.LogError(ex.ToString());
            }
        }