在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. golang:net/http理解总结

    Go语言标准库内建提供了net/http包,涵盖了HTTP客户端和服务端的具体实现.使用net/http包,我们可以很方便地编写HTTP客户端或服务端的程序. http服务端的创建流程 在使用http ...

  2. 强哥MySQL学习笔记

    数据库服务器:1.数据库2.数据表 数据表:1.表结构(字段)2.表数据(记录)3.表索引(加快检索) 表引擎:1.myisam2.innodb 查看表字段desc table;删除数据库:drop ...

  3. VFB FEEDBACK

  4. Tomcat参数

    解析Tomcat的启动脚本--startup.bat:https://www.jb51.net/article/99857.htm 解析Tomcat的启动脚本--catalina.bat:https: ...

  5. 《Java架构师的最佳实践》生产环境JVM调优之空间担保失败引起的FullGC

    1  问题现象 应用prod-xxx-k8s,在内存足够的情况下,仍然会产生偶发FullGC的问题. JVM配置如下: -Xmx8192m -Dhsf.server.max.poolsize=2500 ...

  6. Python使用 Kubernetes API 访问集群

    通过将身份认证令牌直接传给 API 服务器,可以避免使用 kubectl 代理,像这样:使用 grep/cut 方式: 通过将身份认证令牌直接传给 API 服务器,可以避免使用 kubectl 代理, ...

  7. unity ab包打包和加载的简单学习示例

    闲着没事结合项目看了下unity AssetBundle打包和使用,写了一些测试例子,需要的可以拿去,导入一个空项目即可 链接:https://pan.baidu.com/s/1H85dnMNkRoW ...

  8. Django(39)使用redis配置缓存

    前言   动态网站的基本权衡是,它们是动态的.每次用户请求页面时,Web服务器都会进行各种计算 - 从数据库查询到模板呈现再到业务逻辑 - 以创建站点访问者看到的页面.从处理开销的角度来看,这比标准的 ...

  9. 灵动微电子ARM Cortex M0 MM32F0010 Timer定时器中断定时功能的配置

    灵动微电子ARM Cortex M0 MM32F0010 Timer定时器中断定时功能的配置 目录: 1.Timer1高级定时器Timer3通用定时器Timer14基本定时器简介 2.Timer1高级 ...

  10. openresty 学习笔记六:使用session库

    openresty 学习笔记六:使用session库 lua-resty-session 是一个面向 OpenResty 的安全和灵活的 session 库,它实现了 Secure Cookie Pr ...