public void addAnimationFinishEvent(string animationName, OnAnimationEventFunction callbackFunction) { if (_animationComponent == null) { return; } if (_animationComponent[animationName] == null) { return; } AddAnimationEvent(animationName, _animationComponent[animationName].length, callbackFunction); }
public void AddAnimationEvent(string animationName, float time, OnAnimationEventFunction callbackFunction) { if (_animationComponent == null) { return; } if (_animationComponent[animationName] == null) { return; } // AnimationEvent animEvent = new AnimationEvent(); // animEvent.time = time; // animEvent.functionName = functionName; // _currentAnimationState.clip.AddEvent(animEvent); // Is same with // this.gameObject.SendMessage(animEvent.functionName, animEvent); if (!_animationStateSlotList.ContainsKey(animationName)) { return; } AnimationStateSlot animStateSlot = _animationStateSlotList[animationName]; // Create new event callback AnimationEventCallback callback = new AnimationEventCallback(); callback._triggerTime = time; callback._onAnimationEventFunction = callbackFunction; callback._userData = animStateSlot; callback._isTriggered = false; callback._isEndEvent = false; // Check is animation end event if (_animationComponent[animationName].length == time) { callback._isEndEvent = true; } // Add the time event into callback list animStateSlot.AddEventCallback(callback._triggerTime, callback); }