添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Unity的Aniamtor使用后,里面绑定的属性就会被强制锁定,导致业务层无法做修改。属实有点难受,这篇文章就来分析下,对于锁定的属性,animator是如何处理的。

WriteDefaults

在这里插入图片描述
测试环境介绍:
在这里插入图片描述

cube上绑定animator,其中Test-4-1控制Cube4的Position为(0,10,0),Test-4-2控制Cube4的Position为(10,0,0),Rotation为(0,30,0)。Cube4的默认Postion为(50,50,50),Rotation为(0,0,30)。

属性绑定测试

我们将Aniamtor的默认状态设置为NewState(空状态,没有任何动作文件),运行游戏后,发现Cube4的Postion和Rotation都无法修改,Scale可以修改。设置成Test-4-1或者Test-4-2也是一样,说明Animator会上来将里面控制的所有属性进行锁定,跟动画片段无关。

WriteDefault的作用

上面我们知道了属性绑定是一次性绑定了所有属性,上面的例子中,控制了Postion和Rotation,但是Test-4-1只控制了Positon,那么在播放Test-4-1时,Rotation的数据如何赋值呢?我们分析下,此时Rotation的数据的来源有两处,第一处为:播放Test-4-1时,此时Rotaion的数据。第二处:Animator进行Bind时(一般情况下在每次被激活时),锁定所有属性时,Cube4的Rotation的数据,其实就是默认的数据。
如果我们勾选了WriteDefault,就使用第二处数据,没勾选则会使用第一处数据。
所以WriteDefault的含义就是,当动画播放时,如何处理那些当前动画片段不控制的但是被Animator的属性的数值。

多个Animator控制一个属性时,控制权归属

测试举例,在上个例子中(Aniamtor绑定在Cube上),我们在Cube4上加入动画控制器,其中Test-4-Only会控制,Cube4的Postion,Rotation,Scale.
在这里插入图片描述

同时播放Test-4-1(只控制Positon),和Test-4-Only。结果是Postion和Rotation由Cube上的Animator进行控制,Scale由Cube4上的Animator控制。
经过多次测试:当多个Animator控制一个属性时,此属性的控制权选择顺序为:1.UpdateMode:Normal=UnsacledTime>AnimatePhysics 2.由层级更高的Animator>层级低的Animator。

Timeline中的Animation的属性控制

Track相当于AnimatorController,运行时会锁定轨道上的所有属性。
在这里插入图片描述
1使用Default数据,2使用R1最后一帧的数据,3使用R3第一帧数据,4使用Default数据5使用R4最后一帧数据。具体使用哪个数据可以通过clip调整AnimationExtrapolation来实现,如图所示
在这里插入图片描述

Simple Mirror Animation Unity 动画镜像翻转插件,Mirroring character animation s should not just be a Mecanim only feature. With the Simple Mirror Animation asset, legacy character animation mirroring is now possible. No need for extra animation clips, mirroring is done at runtime without any extra overhead or performance cost. This saves not only the burden of creating extra clips, it also reduces build size as a result. Have a weapon parented to your character? Simple Mirror Animation will even mirror parented objects as well! Animator动画控制器组件存在某一个动画片段控制过那个被锁死的 属性 !即使没播放中,除非你完全禁用Animator或删除Animator。代码Update或FixUpdate、LateUpdate等每帧执行函数(或每秒执行函数...)一直在控制着 属性 !②(最好)添加新的父物体,控制它的父物体(进行缩放、位移、旋转)来间接控制它。①禁用Animator 或 删掉它 换形式播放动画(比如 DOTWEEN)哎,第二个情况真的是一直都没有解决啊 Unity 咋回事捏。需要加bool或改控制形式。 Paperback: 175 pages Publisher: Packt Publishing - ebooks Account (June 30, 2015) Language: English ISBN-10: 1782174818 ISBN-13: 978-1782174813 Bring your characters to life with the latest features of Unity and Mecanim About This Book Learn the latest features of Unity 5 to develop the most amazing animation s for all types of games Refine your character animation s by applying more advanced workflows and techniques with Mecanim A comprehensive book that explores core animation concepts and demonstrates their practical application in games Who This Book Is For This book is targeted at hobbyists, students, and game development professionals familiar with the Unity basics, looking to extend their skills and knowledge in the field of real-time game animation . You will need to be familiar with level design and basic scripting in C# and have a good knowledge of game development. What You Will Learn Understand the latest features of Unity 5 such as state machines, meshes, and animation graphs Move, transform, and change objects over time using script files Use the animation editor and curve tools Import and configure externally created animation s for use in Unity scenes See how to link animation s to C# script Animate cameras and create a particle system Produce sophisticated sprite animation s for both 2D and 3D games Apply more advanced workflows and techniques to refine character animation s https://forum. unity .com/threads/animator-locking-animated-value-even-when-current-state-has-no-curves-keys-for-that-value.440363/ 以上链接并未解决问题,因为官方从12年到现在 都不觉得这是个问题。但是实际用的时候确实非常难受,clip中用到的 属性 ,包括setactive ,enable, position等的 修改 ,在其他地方都要用到。不被脚本 修改 是不现实的。 当前的方案是: Unity 提供了 Animation 编辑器,它可以为我们编辑物理动画。举个例子比如场景中有一个来回摇动的秋千,这个秋千在项目中完全只起到衬托作用,它不会与别的 游戏 对象有任何交互。如果这个秋千也用代码来写控制它来回摇动,会感觉小题大做。此时完全可以使用 Animation 编辑器来完成。但是它目前还不能编辑 FK 和 IK动画,所以编辑器中编辑动画的种类还是有限的,如果有一天FK 和 IK动画都可以在Un 编辑器扩展算是比较纯粹的功能开发,基本没有什么理论知识,都是一些 Unity 相关接口的使用与数据类型的设计操作等。在本篇文章主要的文字描述基本都是在做代码解释,为了使内容接受度更高,我会尽量描述到代码结构中的每个细节。如果有对此不太了解又很感兴趣的小伙伴可以尝试手动过一遍代码,相信很快很快就可以掌握编辑器开发方面的使用技巧在前篇文章中有对编辑器扩展UI控件方面的一些基础内容做了简单的描述,大概说明了 Unity Unity 编辑器扩展 UI控件篇。 经过第二关的练习,你已经理解了如何利用"精确 数值 "扫描查找 数值 了,让我们进行下一步,本关主要用来搜索进度条,人物血条等,因为这些数据通常是一个进度条,我们 无法 直接看到的数据,此时可以通过变更的数据一步步筛选找到动态地址。......