public virtual void OnMotionEnd(Motion motion) { if (PlayOnMotionEnd && EndTime > 0) { if (DelayHandler != null && DelayHandler.Active) { DelayHandler.Cancel(); } DelayHandler = new Timer.Handle(); Timer.In(EndTime, OnTimerEnd); OnTimerBegin(); } else if (DontStopOnMotionEnd) { float deltaTime = EndTime - motion.CurrentTime; if (deltaTime <= 0) { OnEnd(motion); } else { if (DelayHandler != null && DelayHandler.Active) { DelayHandler.Cancel(); } DelayHandler = new Timer.Handle(); Timer.In(deltaTime, OnTimerEnd); } } }
/// <summary> /// cancels a timer if the passed timer handle is still active /// </summary> private static void Cancel(Timer.Handle handle) { if (handle == null) { return; } // NOTE: the below Active check is super-important for verifying timer // handle integrity. recycling 'handle.Event' if 'handle.Active' is false // will cancel the wrong event and lead to some other timer never firing // (this is because timer events are recycled but not their timer handles). if (handle.Active) { // setting the 'Id' property to zero will result in DueTime also // becoming zero, sending the event to 'Execute' in the next frame // where it will be recycled instead of executed handle.Id = 0; return; } }