This commit is contained in:
CortexCore
2023-10-24 23:38:22 +08:00
parent 2c4710bc5d
commit bd40165ade
152 changed files with 3681 additions and 1531 deletions

View File

@@ -5,10 +5,12 @@ namespace BITKit
{
public class AnimatorHelper : MonoBehaviour
{
public Transform root;
void OnAnimatorMove()
[SerializeField] private Transform root;
private void OnAnimatorMove()
{
root?.SendMessage(nameof(OnAnimatorMove));
if (root is not null)
root.SendMessage(nameof(OnAnimatorMove));
}
}
}

View File

@@ -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,13 +53,27 @@ 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)
{
animator.CrossFade(name, duration, index);
name = name.Replace(".", "_");
animator.CrossFade(name, duration, index, normalizedTimeOffset);
}
public void Play(string name, int index = -1, float normalizedTimeOffset = 0)
@@ -82,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()