Exemple #1
0
        /// <summary>
        /// The Coroutine for <see cref="SetDayTimeWithAnimation"/>.
        /// </summary>
        private IEnumerator DayTimeAnimation(float newTimeOfDay, float animationTime, Action onFinished = null)
        {
            // Prevents multiple animations
            _isAnimating = true;

            float time         = 0;
            float oldTimeOfDay = clock.TimeOfDay;

            // Used for going to the next day e.g. from 0.8 to 0.3
            if (newTimeOfDay < oldTimeOfDay)
            {
                newTimeOfDay += 1;
                clock.AddOneDay();
            }

            while (time < animationTime)
            {
                time += Time.deltaTime;
                float lerpTime = Mathf.Lerp(oldTimeOfDay, newTimeOfDay,
                                            animationCurve.Evaluate(time * (1 / animationTime)));
                // Next day?
                if (lerpTime > 1)
                {
                    lerpTime -= 1;
                }
                SetTimeOfDay(lerpTime);
                yield return(null);
            }

            _isAnimating = false;
            onFinished?.Invoke();
        }