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.Linq;
using UnityEngine;
using BITKit;
using UnityEngine.Animations;
@@ -13,13 +14,33 @@ namespace BITKit.Animations
{
public class UnityAnimatorStateInfo : StateMachineBehaviour
{
[SerializeReference, SubclassSelector] public References stateName;
[SerializeReference, SubclassSelector] private References stateName;
[SerializeReference,SubclassSelector] private IReference[] variableNames;
public IAnimator animator;
public int index;
private int _index;
public float duration;
[SerializeReference, SubclassSelector] public References[] variables;
[SerializeReference, SubclassSelector] private References[] variables;
public string StateName
{
get
{
try
{
return stateName;
}
catch (Exception e)
{
BIT4Log.Warning<UnityAnimatorStateInfo>(this);
throw;
}
}
}
public string[] VariableNames => variableNames.Select(x=>x.Get()).ToArray();
public string[] VariableAnimationNames => variables.Select(x=>x.Get()).ToArray();
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
_index = layerIndex;
EnsureCreation(animator);
try
{
@@ -41,12 +62,12 @@ namespace BITKit.Animations
public override void OnStateMachineEnter(Animator animator, int stateMachinePathHash)
{
EnsureCreation(animator);
this.animator?.OnStateEnter(index, stateName);
this.animator?.OnStateEnter(_index, stateName);
}
public override void OnStateMachineExit(Animator animator, int stateMachinePathHash)
{
EnsureCreation(animator);
this.animator?.OnStateExit(index, stateName);
this.animator?.OnStateExit(_index, stateName);
}
public void Play()
@@ -57,7 +78,7 @@ namespace BITKit.Animations
}
else
{
animator.CrossFade(stateName, duration, index);
animator.CrossFade(stateName, duration, _index);
}
}
void EnsureCreation(Animator animator)