public void Update(float dt) { _timer?.UpdateTimer(dt); }
public void Update(float dt) { if (null != _curAnim) { int spriteCount = _curAnim.sprites.Count; // update delay if (null != _timerDelay) { _timerDelay.UpdateTimer(dt); return; } // update timer here if (!_timer.UpdateTimer(dt)) { _timer.Reset(); _curIdx = _curIdx + (_isBackwards ? -1 : 1); // if it should loop... if (_curAnim.ShouldLoop) { // check whether has reached bottom / upper limit bool hasReachedLimit = _curAnim.pingPong ? (_isBackwards ? _curIdx < 0 : _curIdx >= spriteCount) : _curIdx >= spriteCount; // if has reached limit if (hasReachedLimit) { // if pingpong, toggle the backwards flag // otherwise reset cur idx to 0 again if (_curAnim.pingPong) { _isBackwards = !_isBackwards; } else { _curIdx = 0; } ++_counter; TryInitDelay(); } } // make sure the index wont be out of bound _curIdx = _curIdx.Clamp(0, spriteCount - 1); } // check loop count here bool isDone = false; bool shouldChangeSprite = false; if (_curAnim.LoopForever) { shouldChangeSprite = true; } else { if ((_curAnim.ShouldLoop && _counter > _curAnim.loop)) { isDone = true; } else { shouldChangeSprite = true; if (!_curAnim.ShouldLoop && _curIdx == spriteCount - 1) { isDone = true; } } } if (shouldChangeSprite) { var curSprite = _curAnim.sprites[_curIdx]; CurSprite?.Invoke(curSprite); } if (isDone) { _onDone?.Invoke(); _curAnim = null; } } }