using System.Collections; using System.Collections.Generic; using UnityEngine; namespace BITKit { public class AnimatorStateHelper : StateMachineBehaviour { public string stateName; IGenericEvent genericEvent; public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { EnsureValid(animator); genericEvent?.Invoke(Constant.Animation.OnPlay, stateName); } public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { EnsureValid(animator); genericEvent?.Invoke(stateName, stateInfo); } public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { EnsureValid(animator); genericEvent?.Invoke(Constant.Animation.OnPlayEnd, stateName); genericEvent?.Invoke(stateName, new()); } void EnsureValid(Animator animator) { if (genericEvent is null) { genericEvent = animator.GetComponent>(); } } } }