using System.Collections; using System.Collections.Generic; using UnityEngine; public class ActiveClipRegistration : StateMachineBehaviour { AnimationEventHandler animationEventHandler; int stateNameHash; List clips = new List(); public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { base.OnStateExit(animator, stateInfo, layerIndex); foreach(AnimationClip clip in clips) animationEventHandler?.UnregisterFromActiveClip(clip); clips.Clear(); } public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { base.OnStateEnter(animator, stateInfo, layerIndex); if (animator.GetLayerWeight(layerIndex) == 0) return; if (animationEventHandler == null) animationEventHandler = animator.GetComponent(); for (int i = 0; i < animator.GetNextAnimatorClipInfo(layerIndex).Length; i++) { AnimationClip clip = animator.GetNextAnimatorClipInfo(layerIndex)[i].clip; clips.Add(clip); animationEventHandler.RegisterAsActiveClip(clip); } } }