Beispiel #1
0
        /// <summary>
        /// Updates the animation. Not the part of entity loop,
        /// you need to call it on your own.
        ///
        /// NOTE: If using in Draw method, keep in mind that each camera calls the event separately.
        /// You may want to restrict it only to the first camera.
        /// </summary>
        public void Update()
        {
            if (!Running)
            {
                return;
            }

            if (TimeKeeper == null)
            {
                LinearProgress += TimeKeeper.GlobalTime(Math.Abs(Speed));
            }
            else
            {
                LinearProgress += TimeKeeper.Time(Math.Abs(Speed));
            }

            if (LinearProgress > 1)
            {
                if (!Looping)
                {
                    Running        = false;
                    LinearProgress = 1;
                }
                else
                {
                    LinearProgress -= (int)LinearProgress;
                }

                AnimationEndEvent?.Invoke(this);
            }
        }
Beispiel #2
0
    private IEnumerator Animate(Step from, Step to, float duration, StepManager.Lerp lerp)
    {
        if (stance.Pivot == Stance.Foot.Left)
        {
            stance.Right = from;
        }
        else
        {
            stance.Left = from;
        }

        Delegate?.Invoke(true);

        yield return(null);

        for (float t = Time.deltaTime; t < duration; t += Time.deltaTime)
        {
            if (stance.Pivot == Stance.Foot.Left)
            {
                stance.Right = lerp(from, to, t / duration);
            }
            else
            {
                stance.Left = lerp(from, to, t / duration);
            }

            yield return(null);
        }

        if (stance.Pivot == Stance.Foot.Left)
        {
            stance.Right = to;
            stance.Pivot = Stance.Foot.Right;
        }
        else
        {
            stance.Left  = to;
            stance.Pivot = Stance.Foot.Left;
        }

        coroutine = null;

        Delegate?.Invoke(false);
    }