This commit is contained in:
CortexCore
2023-06-05 16:25:06 +08:00
parent 9027120bb8
commit 4565ff2e35
2947 changed files with 0 additions and 0 deletions

View File

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