1
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user