/// <summary> /// Advance animation and return current animation step index. /// </summary> /// <param name="timeFactor">Time factor for animation playing speed.</param> /// <returns>Current animation step index.</returns> public int Update(float timeFactor) { // if finished, return last index and stop here if (_isDone) { return(CurrentStep); } // advance current step _timeForNextStep -= timeFactor * SpeedFactor; // did we finish current step? if (_timeForNextStep <= 0f) { // advance current animation step CurrentStep++; // did we finish animation clip? if (CurrentStep > Clip.EndIndex) { // if its looping, just start over if (Clip.IsLooping) { CurrentStep = Clip.StartIndex; } // if not looping, mark as done and return to last step to get "stuck" on else { _isDone = true; CurrentStep = Clip.EndIndex; } // invoke finish animation callback OnAnimationEnd?.Invoke(); } // get time until next step _timeForNextStep = Clip.DelayForStep(CurrentStep - Clip.StartIndex); } // return current animation step return(CurrentStep); }