/// Bind an event listener to any animation triggers on the object /// If the Func returns true, the event is removed. /// ie. Check for 'End' or 'Start' and return true if its the desired target. public static void OnAnimationTrigger(this Animator target, Func <AnimationTriggerEvent, bool> handler) { var receiver = AnimationEventReceiver.For(target.gameObject); Action <AnimationTriggerEvent> wrapper = null; wrapper = (ep) => { if (handler(ep)) { receiver.EventHandler.RemoveEventHandler(wrapper); } }; receiver.EventHandler.AddEventHandler(wrapper); }
public sealed override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { GameObject = animator.gameObject; Receiver = AnimationEventReceiver.For(GameObject); Start(); }