Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEngine;
using UniRx;
public class AnimatorBehaviourBase : StateMachineBehaviour
{
float enterTime;
public ReactiveProperty<float> NormalizedTime { get; private set; }
public ReactiveProperty<bool> IsTransition { get; private set; }
public CompositeDisposable exitDisposable;
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
NormalizedTime = new ReactiveProperty<float>(0.0f);
IsTransition = new ReactiveProperty<bool>(animator.IsInTransition(layerIndex));
exitDisposable = new CompositeDisposable();
enterTime = 0.0f;//Time.time;
StateEnter(animator, stateInfo, layerIndex);
}
public virtual void StateEnter(Animator animator, AnimatorStateInfo stateinfo, int layerIndex)
{
}
//TODO:IsTransitionしてるときずれてるかもなあ
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if(!IsTransition.Value) NormalizedTime.Value = stateInfo.normalizedTime - enterTime;//((Time.time - enterTime) * stateInfo.speed) / stateInfo.length;
IsTransition.Value = animator.IsInTransition(layerIndex);
StateUpdate(animator, stateInfo, layerIndex);
}
public virtual void StateUpdate(Animator animator, AnimatorStateInfo stateinfo, int layerIndex)
{
}
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
StateExit(animator, stateInfo, layerIndex);
}
public virtual void StateExit(Animator animator, AnimatorStateInfo stateinfo, int layerIndex)
{
if(exitDisposable != null)
exitDisposable.Dispose();
}
public void ResetTime(float time)
{
enterTime = time;//Time.time;
NormalizedTime.Value = 0.0f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.