1
This commit is contained in:
@@ -10,17 +10,12 @@ namespace BITKit.Animations
|
||||
{
|
||||
public class UnityAnimator : MonoBehaviour, IAnimator
|
||||
{
|
||||
[System.Serializable]
|
||||
public record AnimatorPlayEvent
|
||||
{
|
||||
public string stateName;
|
||||
public int index;
|
||||
}
|
||||
[System.Serializable]
|
||||
[Serializable]
|
||||
public class AnimatorLayerInfo
|
||||
{
|
||||
public string stateName;
|
||||
public string fullStateName;
|
||||
internal string entryName;
|
||||
public AnimatorStateInfo currentState = new();
|
||||
public event Action<string> onStateEnter;
|
||||
public event Action<string> onStateExit;
|
||||
@@ -33,6 +28,10 @@ namespace BITKit.Animations
|
||||
onStateExit?.Invoke(name);
|
||||
}
|
||||
}
|
||||
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeField] private bool debug;
|
||||
|
||||
[Header(Constant.Header.Components)]
|
||||
public Animator animator;
|
||||
public AnimatorLayerInfo this[int index]
|
||||
@@ -54,10 +53,22 @@ namespace BITKit.Animations
|
||||
return layerInfos[index];
|
||||
}
|
||||
}
|
||||
public List<AnimatorLayerInfo> layerInfos = new();
|
||||
|
||||
[SerializeField] private List<AnimatorLayerInfo> layerInfos = new();
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
private readonly Dictionary<string,UnityAnimatorStateInfo> _registryStates=new ();
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
animator.enabled = true;
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
animator.enabled = false;
|
||||
foreach (var x in layerInfos)
|
||||
{
|
||||
x.entryName = null;
|
||||
}
|
||||
}
|
||||
public void CrossFade(string name, float duration, int index = 0, float normalizedTimeOffset = 0)
|
||||
{
|
||||
name = name.Replace(".", "_");
|
||||
@@ -84,17 +95,29 @@ namespace BITKit.Animations
|
||||
|
||||
public void OnStateEnter(int index, string name)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
BIT4Log.Log<UnityAnimator>($"OnEntry:{name}");
|
||||
}
|
||||
this[index].fullStateName = name;
|
||||
foreach (var item in name.Split("."))
|
||||
{
|
||||
name = item;
|
||||
break;
|
||||
}
|
||||
this[index].stateName = name;
|
||||
this[index].stateName = this[index].entryName = name;
|
||||
this[index].OnStateEnter(name);
|
||||
}
|
||||
public void OnStateExit(int index, string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(this[index].entryName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (debug)
|
||||
{
|
||||
BIT4Log.Log<UnityAnimator>($"OnExit:{name}");
|
||||
}
|
||||
this[index].OnStateExit(name);
|
||||
}
|
||||
public float3 GetRootVelocity()
|
||||
|
Reference in New Issue
Block a user