在unity animator中单个Animator Clip中点击Add Behaviour增加当执行该动画时的一些状态代码,请看如下

创建完之后基本代码结构如下:(如果想修改默认代码结构,请看示例:教程示例

1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4
5 public class Hero_walk : StateMachineBehaviour
6 {
7 // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
8 //override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
9 //{
10 //
11 //}
12
13 // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
14 //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
15 //{
16 //
17 //}
18
19 // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
20 //override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
21 //{
22 //
23 //}
24
25 // OnStateMove is called right after Animator.OnAnimatorMove()
26 //override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
27 //{
28 // // Implement code that processes and affects root motion
29 //}
30
31 // OnStateIK is called right after Animator.OnAnimatorIK()
32 //override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
33 //{
34 // // Implement code that sets up animation IK (inverse kinematics)
35 //}
36 }

我们在来看一下StateMachineBehaviour元数据

 1 #region 程序集 UnityEngine.AnimationModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
2 // D:\WorkTools\Unity\2019.4.16f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.AnimationModule.dll
3 #endregion
4
5 using UnityEngine.Animations;
6 using UnityEngine.Scripting;
7
8 namespace UnityEngine
9 {
10 //
11 // 摘要:
12 // StateMachineBehaviour is a component that can be added to a state machine state.
13 // It's the base class every script on a state derives from.
14 [RequiredByNativeCode]
15 public abstract class StateMachineBehaviour : ScriptableObject
16 {
17 protected StateMachineBehaviour();
18
19 public virtual void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex);
20 public virtual void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex, AnimatorControllerPlayable controller);
21 public virtual void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex);
22 public virtual void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex, AnimatorControllerPlayable controller);
23 public virtual void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex);
24 public virtual void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex, AnimatorControllerPlayable controller);
25 //
26 // 摘要:
27 // Called on the first Update frame when making a transition to a state machine.
28 // This is not called when making a transition into a state machine sub-state.
29 //
30 // 参数:
31 // animator:
32 // The Animator playing this state machine.
33 //
34 // stateMachinePathHash:
35 // The full path hash for this state machine.
36 public virtual void OnStateMachineEnter(Animator animator, int stateMachinePathHash);
37 public virtual void OnStateMachineEnter(Animator animator, int stateMachinePathHash, AnimatorControllerPlayable controller);
38 //
39 // 摘要:
40 // Called on the last Update frame when making a transition out of a StateMachine.
41 // This is not called when making a transition into a StateMachine sub-state.
42 //
43 // 参数:
44 // animator:
45 // The Animator playing this state machine.
46 //
47 // stateMachinePathHash:
48 // The full path hash for this state machine.
49 public virtual void OnStateMachineExit(Animator animator, int stateMachinePathHash);
50 public virtual void OnStateMachineExit(Animator animator, int stateMachinePathHash, AnimatorControllerPlayable controller);
51 public virtual void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex);
52 public virtual void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex, AnimatorControllerPlayable controller);
53 public virtual void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex);
54 public virtual void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex, AnimatorControllerPlayable controller);
55 }
56 }

是不是很方便呢,今天刚好找到了这个东西

Unity StateMachineBehaviour的更多相关文章

  1. Unity的stateMachineBehaviour

    Unity5新增的StateMachineBehaviour是对状态机的内置,确实方便了很多,这里记录它的两个问题: 1.如果正在执行的状态被打断,当前状态的OnStateExit不会被执行,该问题在 ...

  2. Unity 动画系统 StateMachineBehaviour 动画状态机

  3. Unity-Animator深入系列---StateMachineBehaviour初始化时间测试

    回到 Animator深入系列总目录 结果和想的有点出入 测试结果: 1.SMB初始化会被调用多次,次数不可控,当Animator组件重复开关则重复初始化. 2.SMB支持构造函数 MyClass p ...

  4. 从Unity中的Attribute到AOP(七)

    本章我们将依然讲解Unity中的Attribute,继续命名空间在UnityEngine里的. PropertyAttribute,这个特性主要来控制变量或者类在Inspector里面的显示方式.和P ...

  5. 关于Unity中Mecanim动画的动画状态代码控制与代码生成动画控制器

    对于多量的.复杂的.有规律的控制器使用代码生成 动画状态代码控制 1:每个动画状态,比如进入状态,离开状态, 等都有可能需要代码来参与和处理,比如,进入这个动画单元后做哪些事情,来开这个动画单元后做哪 ...

  6. 【Unity】状态机的状态改变及其回调

    问:怎么知道状态机发生了改变?即如何得知从一个状态切换到了另一个状态? 答:Unity使用StateMachineBehaviours类来描述状态机的行为,当状态机处于不同的状态时,会触发不同的回调. ...

  7. Unity 动画系统目录 之 Animation

    返回 Unity 动画系统目录 官方文档 Animation:https://docs.unity3d.com/ScriptReference/Animation.html Animator:http ...

  8. Unity C# 关于Attribute的使用

    最近在研究Attribute,感觉挺好玩,搜到一篇不错的文章,分享给大家 原文:未知?找到后补上! 举两个例子,在变量上使用[SerializeFiled]属性,可以强制让变量进行序列化,可以在Uni ...

  9. Unity3d入门 - 关于unity工具的熟悉

    上周由于工作内容较多,花在unity上学习的时间不多,但总归还是学习了一些东西,内容如下: .1 根据相关的教程在mac上安装了unity. .2 学习了unity的主要的工具分布和对应工具的相关的功 ...

随机推荐

  1. CRM系统实现自动化的“三部曲”

    在了解CRM系统的自动化的时候,我们先来看一下CRM能干什么. 从上面的流程图我们就可以看出,CRM可以管理售前,售中和售后的整个客户生命周期. 为什么在复杂的客户生命周期中需要自动化呢? 当然是为了 ...

  2. MakeCode图形编程应用在micro:bit上的多工性能实测

    1. 简述 本文不涉及对测试中所用到的设备或软件的推广. micro:bit 是一款由英国广播电视公司(BBC)为青少年编程教育设计,并由微软,三星,ARM,英国兰卡斯特大学等合作伙伴共同完成开发的微 ...

  3. JMeter四种参数化方式

    JMeter参数化是指把固定的数据动态化,这样更贴合实际的模拟用户请求,比如模拟多个不同账号.JMeter一共有四种参数化方式,分别是: CSV Data Set Config Function He ...

  4. 解决nohup: 忽略输入并把输出追加到"nohup.out"或者nohup: 忽略输入重定向错误到标准输出端

    nohup启动脚本的时候,没有指定输出路径,默认使用当前目录的nohup.out 例如下面这句就是默认使用nohup.out作为输出文件: nohup script.sh & 改成下面的,则/ ...

  5. [Java] HOW2J(Java中级)

    异常 定义:导致程序正常流程被中断的事件 异常处理常见手段 try catch:将可能抛出异常的代码放在try的块中,一旦出现异常就跳转到catch的块中处理 throws/throw:不在本模块处理 ...

  6. 保存 yum 下载的软件包并制作成本地 yum 源

    保存 yum 下载的软件包并制作成本地 yum 源 实验对象 CentOS 7 yum 安装 nginx (nginx必须使用第三源才能安装:redhat8版本的则不需要,官网源自带nginx软件包) ...

  7. Zabbix 自定义report

    #!/bin/bash . /etc/profile logdir='/home/admin/zabbix/zabbix_log' mysql_host='localhost' mysql_user= ...

  8. Centos6下通过 oprofile分析CPU性能

    Centos6下通过 oprofile分析CPU性能 2014-01-18 10:55:15 bobpen 阅读数 2218更多 分类专栏: linux   版权声明:本文为博主原创文章,遵循CC 4 ...

  9. Linux进阶之TCP三次握手四次挥手

    TCP(Transfer control protocol)传输控制协议 一.两种传输模式: TCP面向有连接 可靠 常用于点对点 微信 UDP面向无连接 高速 常用于点对面 直播 二.数据方向: 在 ...

  10. 几种新的MCU开发环境和语言

    https://kuaibao.qq.com/s/20171108A0LQST00?refer=kb_news 桥大学数学科学中心的Damien P. George在研究各种深奥数学.物理问题之余,还 ...