/// <summary> /// Update the animation. /// </summary> public void Update(float dt) { if (IsPaused) { return; } if (wantToChangedTag != null) { ReallySetTag(wantToChangedTag, wantToChangedTagReverseMode); wantToChangedTag = null; wantToChangedTagReverseMode = false; } if (wantToSetFrameIndexFlag) { SetFrameImmediately(wantToSetFrameIndex); } if (dt == 0) { return; } if (dt < 0) { throw new Exception($"{nameof(dt)} must be positive"); } if (currentTag == null) { throw new Exception("not set tag yet"); } string currentExecuteTagName = currentTag.Name; // invoke .... if (isNeedStartToCallFrameAction) { FrameBegin?.Invoke(currentExecuteTagName, CurrentFrameIndex); isNeedStartToCallFrameAction = false; } if (currentTag.loopTime) { var lastFrame = CurrentFrameIndex; ElapsedTimeMoveFrame_LoopMode(CurrentFrameIndex, TimeElapsed, dt, out var beginFrameList, out var endFrameList); foreach (var itemIndex in beginFrameList) { FrameBegin?.Invoke(currentExecuteTagName, itemIndex); } foreach (var itemIndex in endFrameList) { FrameEnd?.Invoke(currentExecuteTagName, itemIndex); } if (beginFrameList.Count > 0) { CurrentFrameIndex = beginFrameList[beginFrameList.Count - 1]; } // add the remain .... TimeElapsed += dt; } else { var lastFrameIndex = currentTag.Frames.Count - 1; if (CurrentFrameIndex == lastFrameIndex && TimeElapsed > currentTag.Duration) { // do nothing ... } else { var curFrame = CurrentFrameIndex; ElapsedTimeMoveFrame_NoLoopMode(CurrentFrameIndex, TimeElapsed, dt, out var beginFrameList, out var endFrameList); foreach (var itemIndex in beginFrameList) { FrameBegin?.Invoke(currentExecuteTagName, itemIndex); } foreach (var itemIndex in endFrameList) { FrameEnd?.Invoke(currentExecuteTagName, itemIndex); } // add the remain .... if (beginFrameList.Count > 0) { CurrentFrameIndex = beginFrameList[beginFrameList.Count - 1]; } TimeElapsed += dt; } } }
protected virtual void OnFrameEnd(RenderTimer timer) { FrameEnd?.Invoke(this, new FrameStageEventArgs(timer)); }
/// <summary> /// Raises the <see cref="FrameEnd"/> event. /// </summary> protected virtual void OnFrameEnd() => FrameEnd?.Invoke(this);