鸟语天空
StateMachineBehaviour
post by:追风剑情 2019-10-21 11:11

一、工程截图

1111.png

2222.png


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Animations;
/// <summary>
/// 状态机行为
/// 获取行为类对象: animator.GetBehaviour<statemachinebehaviourtest>()
/// </summary>
public class StateMachineBehaviourTest : StateMachineBehaviour
{
    //进入当前状态
    public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) 
    {
        Debug.Log("OnStateEnter_0");
    }
    public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex, AnimatorControllerPlayable controller)
    {
        Debug.Log("OnStateEnter_1");
    }
    //离开当前状态
    public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        Debug.Log("OnStateExit_0");
    }
    public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex, AnimatorControllerPlayable controller) 
    {
        Debug.Log("OnStateExit_1");
    }
    //在MonoBehaviour.OnAnimatorIK之后立即调用。
    public override void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) 
    {
        Debug.Log("OnStateIK_0");
    }
    public override void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex, AnimatorControllerPlayable controller)
    {
        Debug.Log("OnStateIK_1");
    }
    //过渡到状态机时在第一个Update帧上调用。过渡到状态机子状态时,不会调用此方法。
    public override void OnStateMachineEnter(Animator animator, int stateMachinePathHash) 
    {
        Debug.Log("OnStateMachineEnter_0");
    }
    public override void OnStateMachineEnter(Animator animator, int stateMachinePathHash, AnimatorControllerPlayable controller) 
    {
        Debug.Log("OnStateMachineEnter_1");
    }
    //从StateMachine过渡出来时,调用最后一个Update帧。过渡到StateMachine子状态时,不会调用此方法。
    public override void OnStateMachineExit(Animator animator, int stateMachinePathHash) 
    {
        Debug.Log("OnStateMachineExit_0");
    }
    public override void OnStateMachineExit(Animator animator, int stateMachinePathHash, AnimatorControllerPlayable controller) 
    {
        Debug.Log("OnStateMachineExit_1");
    }
    //在MonoBehaviour.OnAnimatorMove之后立即调用。
    public override void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        Debug.Log("OnStateMove_0");
    }
    public override void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex, AnimatorControllerPlayable controller) 
    {
        Debug.Log("OnStateMove_1");
    }
    //在第一帧和最后一帧之外的每个更新帧中调用。
    public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) 
    {
        Debug.Log("OnStateUpdate_0");
    }
    public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex, AnimatorControllerPlayable controller) 
    {
        Debug.Log("OnStateUpdate__1");
    }
}


二、运行测试

3333.png

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容