public void PlayAnimation(string animationName, float speed, bool loop, bool autoStop) { if (_animationComponent == null) { return; } if (_animationComponent[animationName] == null) { return; } AnimationState animState = _animationComponent[animationName]; // The default layer value, the 0 is the low layer,the top layer is cross first animState.layer = 0; animState.time = 0.0f; animState.weight = 1.0f; animState.speed = speed; // The Loop animation control animState.wrapMode = loop ? WrapMode.Loop : WrapMode.Once; if (_animationStateSlotList.ContainsKey(animationName)) { _animationStateSlotList.Remove(animationName); } AnimationStateSlot animationStateSlot = new AnimationStateSlot(animState); _animationStateSlotList.Add(animationName, animationStateSlot); _animationComponent.CrossFade(animationName); // _animationComponent.Play(animationName); }
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); }