This commit is contained in:
CortexCore
2023-11-15 23:55:06 +08:00
parent 5446067f91
commit 70247f0242
82 changed files with 3271 additions and 579 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using Cysharp.Threading.Tasks;
using System.Threading;
@@ -13,6 +14,7 @@ namespace BITKit.Animations
[Serializable]
public class AnimatorLayerInfo
{
public string LayerName;
public string stateName;
public string fullStateName;
internal string entryName;
@@ -42,7 +44,11 @@ namespace BITKit.Animations
{
for (int i = layerInfos.Count - 1; i < index; i++)
{
layerInfos.Add(new());
var newLayer = new AnimatorLayerInfo
{
LayerName = animator.GetLayerName(i+1)
};
layerInfos.Add(newLayer);
}
}
@@ -69,28 +75,18 @@ namespace BITKit.Animations
x.entryName = null;
}
}
public void CrossFade(string name, float duration, int index = 0, float normalizedTimeOffset = 0)
public void CrossFade(string animationName, float duration, int index = 0, float normalizedTimeOffset = 0)
{
name = name.Replace(".", "_");
animator.CrossFade(name, duration, index, normalizedTimeOffset);
animator.CrossFade(GetVariableName(animationName), duration, index, normalizedTimeOffset);
}
public void Play(string name, int index = -1, float normalizedTimeOffset = 0)
public void Play(string animationName, int index = -1, float normalizedTimeOffset = 0)
{
name = name.Replace(".", "_");
if (_registryStates.TryGetValue(name, out var stateInfo) && stateInfo.variables?.Length > 0)
if (debug)
{
name = stateInfo.variables.Random();
BIT4Log.Log<UnityAnimator>( $"{gameObject.name} Play:" + animationName);
}
animator.Play(name, index, normalizedTimeOffset);
}
public void Play(string name)
{
Play(name,-1,0);
animator.Play(GetVariableName(animationName), index, normalizedTimeOffset);
}
public void OnStateEnter(int index, string name)
@@ -129,7 +125,20 @@ namespace BITKit.Animations
{
foreach (var x in animator.GetBehaviours<UnityAnimatorStateInfo>())
{
_registryStates.TryAdd(x.stateName, x);
try
{
_registryStates.TryAdd(x.StateName, x);
foreach (var v in x.VariableNames)
{
_registryStates.TryAdd(v, x);
}
}
catch (Exception e)
{
BIT4Log.Warning<UnityAnimator>(gameObject.name);
throw;
}
}
}
@@ -140,5 +149,26 @@ namespace BITKit.Animations
this[i].currentState = animator.GetCurrentAnimatorStateInfo(i);
}
}
[ContextMenu(nameof(Diagnosis))]
private void Diagnosis()
{
}
private string GetVariableName(string animationName)
{
animationName = animationName.Replace(".", "_");
if (!_registryStates.TryGetValue(animationName, out var stateInfo)) return animationName;
animationName = stateInfo.StateName;
if (stateInfo.VariableAnimationNames.Length > 0)
{
animationName = stateInfo.VariableAnimationNames.Random();
}
return animationName;
}
}
}