来自官方2014-06-26新闻
原文: http://www.unitymanual.com/thread-18449-1-1.html
小编的话:这是一篇关于unity新动画功能的文章,有原文和译文(有译错的地方还请各位包含)。文章主要介绍的部分有:State Machine Behaviours, 状态机转换,资源创建器接口,直接混合树,根运动的创建等。原文有图解和代码,小蛮牛们可以好好研究下啊。↖(^ω^)↗
Shiny new animation features in Unity 5.0
Unity5.0中的新酷炫动画功能
June 26, 2014 in Company News and Info, Technology, Unity Products and Services by Pierre Paul Giroux
The animation team has been working hard to pull together an impressive feature set for Unity 5.0. Here’s a quick overview of the new animation features you can look forward to!
动画团队一直在为Unity 5.0增加新功能而努力工作。接下来这篇文章是关于新动画功能的简要概述。
State Machine Behaviours
State Machine Behaviours
In Unity 5, you’ll be able to add StateMachineBehaviour scripts to your states, and receive the following callbacks when the states are played:
在Unity 5中,可以在某些状态中添加StateMachineBehaviour脚本。某些状态出现时,将出现以下几种回调。
• OnStateEnter
• OnStateUpdate
• OnStateExit
• OnStateMove
• OnStateIK
You can have as many StateMachineBehaviours in your State as you like. So to add IK on State, or to do some custom logic, simply drag the StateMachineBehaviour script on to it.
只要我们喜欢,就可以在状态中添加很多StateMachineBehaviours脚本。因此,我们可以在状态中添加OnStateIK,或添加其他自定义逻辑脚本,或仅是把StateMachineBehaviour脚本粘上去。
Basically, anything that requires some kind of StateMachine logic in your game – with or without animation – can use this.
通常情况下,只要游戏中有需要一些StateMachine逻辑的地方,就可以使用StateMachineBehaviours脚本。
Another great thing about this feature is that you don’t need to have tons of
State Machine Behaviours的另个特点是不用再写很多下述这些代码:
[C#] 纯文本查看 复制代码?
12 if(animator.GetCurrentAnimatorStateInfo(0).isName("Idle") ) DoStuff()
(which I’m sure you have plenty of in your code),
(我不确定你们是否要写很多类似这样的代码)
you can just use StateMachineBehaviours instead!
只需用StateMachineBehaviours替代下就行了。
State Machine Transitions
状态机转换
State Machines are growing more and more complex, so we introduced the concept of State Machine Transitions to provide a higher level of abstraction over the StateMachine logic.
因为状态机变得越来越复杂了。我打算介绍下状态机转换,它可在状态机逻辑之上提供给我们更高层次的抽象表示。
In Unity 5, we’ve added Entry and Exit nodes to StateMachines. There are used during State Machine Transitions.
在Unity 5中,我们已在状态机中添加进入和退出节点。这两种节点都在状态及转换中使用。
Entry: When you transition to a StateMachine, the animation system will evaluate the Entry node and branch to the destination that its conditions meet.
进入节点:进行状态机转换时,动画系统将计算进入节点和进入分支到目标节点需要满足的条件。
Exit: When going to the Exit node, the animation system will look at the outgoing StateMachine transitions and branch to the proper destination.
退出节点:到了退出节点时,动画系统将查看已运行的状态机转换并找出更合理的到终节点的路径。
Note that you can mix transitions: State->State, State->StateMachine, StateMachine->StateMachine…
我们可以添加这样的转换类型:State->State, State->StateMachine, StateMachine->StateMachine…
What’s more, we also revamped the UI for our tool so you can now re-order your parameters and layers.
此外,我们还修改了用户工具。因此,可以重新命令参数和图层。
Asset Creation API
资源创建器接口
In Unity 5 you can create animation assets; StateMachines, States, Controllers, Layers, Blentrees, etc., using scripts in the Editor!
在Unity 5中,可以创建动画资源,例如:在编辑器中用脚本创建状态机,状态,控件,图层,树型结构等。
There are two APIs, a high-level one, where the assets are managed by Unity and a low level one where you manage assets manually, and can perform external referencing.
有两种API,一种是由Unity来管理资源的高级别API。另一种是设计者自行管理资源和执行外部引用操作的低级别API。
Both APIs are documented, and I’ve put a small example of API usage at the end of this post.
这两种API我已介绍了。接下来,我将在文章的最后,通过事例来说明API的使用。
Direct Blend Trees
直接混合树
We’ve added a new type of BlendTree that allows you to map an animator parameter to the weight of a BlendTree child directly.
我们已在混合树中添加了新属性,该属性可通过动画控制器参数直接设置混合树子树的权值。
This can come in really handy if you’re working with BlendShape animations, or additive animations.
这样一来,动画融合变形和动画叠加就容易操作了。
Root Motion Authoring (in generic mode)
根运动的创建(常规模式下)
Unity 5 also allows you to animate objects and convert their animator to root motion (ie Delta Animation). Simply create an animation – translation/rotation – on the topmost transform of an object then click Generate Root Motion Curve in the AnimationClip inspector!
Unity 5可以动画绘制物体和创建动画到根运动(比如Delta Animation)。只需创建动画,再转换/平移,然后最外层转换物体。最后在动画剪辑检视面板中单击Generate Root Motion Curve
More stuff that will make your life easier:
• Improved animation previewer camera. The camera can now Pan, Orbit and Scale in the same way as the scene viewer.
• Runtime access to parameters (name, default values etc..)
• Gizmo in scene view for root position, ik position, etc…
• Improved retargeting engine
• Runtime optimizations
• Tons and tons of bug fixes
更多功能,让动画制作更轻松:
• 改进动画预览器相机。现在,相机可以像场景浏览器一样进行平移,旋转和缩放。
• 运行时访问参数(如名称,默认值等)
• 为场景视图中的Gizmo根定位,ik定位等。
• 改进重新目标定位引擎
• 运行时自动优化
• 可以修复大量的错误
Let us know what you think of these changes!
The Animation Team.
告诉我们,你对这些新功能的看法。
我们是动画团队。
Asset Creation API sample Code
资源创建器的示例代码
// Creates the controller
var controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath ("Assets/Mecanim/StateMachineTransitions.controller");
// Add parameters
controller.AddParameter(“TransitionNow”, UnityEditor.Animations.AnimatorControllerParameterType.Trigger);
controller.AddParameter(“Reset”, UnityEditor.Animations.AnimatorControllerParameterType.Trigger);
controller.AddParameter(“GotoB1〃, UnityEditor.Animations.AnimatorControllerParameterType.Trigger);
controller.AddParameter(“GotoC”, UnityEditor.Animations.AnimatorControllerParameterType.Trigger);
// Add StateMachines
var rootStateMachine = controller.layers[0].stateMachine;
var stateMachineA = rootStateMachine.AddStateMachine(“smA”);
var stateMachineB = rootStateMachine.AddStateMachine(“smB”);
var stateMachineC = stateMachineB.AddStateMachine(“smC”);
// Add States
var stateA1 = stateMachineA.AddState(“stateA1〃);
var stateB1 = stateMachineB.AddState(“stateB1〃);
var stateB2 = stateMachineB.AddState(“stateB2〃);
stateMachineC.AddState(“stateC1〃);
var stateC2 = stateMachineC.AddState(“stateC2〃); // don’t add an entry transition, should entry to state by default
// Add Transitions
var exitTransition = stateA1.AddExitTransition();
exitTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “TransitionNow”);
exitTransition.duration = 0;
var resetTransition = stateMachineA.AddAnyStateTransition(stateA1);
resetTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “Reset”);
resetTransition.duration = 0;
var transitionB1 = stateMachineB.AddEntryTransition(stateB1);
transitionB1.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “GotoB1〃);
stateMachineB.AddEntryTransition(stateB2);
stateMachineC.defaultState = stateC2;
var exitTransitionC2 = stateC2.AddExitTransition();
exitTransitionC2.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “TransitionNow”);
exitTransitionC2.duration = 0;
var stateMachineTransition = rootStateMachine.AddStateMachineTransition(stateMachineA, stateMachineC);
stateMachineTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “GotoC”);
rootStateMachine.AddStateMachineTransition(stateMachineA, stateMachineB);
原文: http://www.unitymanual.com/thread-18449-1-1.html
小编的话:这是一篇关于unity新动画功能的文章,有原文和译文(有译错的地方还请各位包含)。文章主要介绍的部分有:State Machine Behaviours, 状态机转换,资源创建器接口,直接混合树,根运动的创建等。原文有图解和代码,小蛮牛们可以好好研究下啊。↖(^ω^)↗
Shiny new animation features in Unity 5.0
Unity5.0中的新酷炫动画功能
June 26, 2014 in Company News and Info, Technology, Unity Products and Services by Pierre Paul Giroux
The animation team has been working hard to pull together an impressive feature set for Unity 5.0. Here’s a quick overview of the new animation features you can look forward to!
动画团队一直在为Unity 5.0增加新功能而努力工作。接下来这篇文章是关于新动画功能的简要概述。
State Machine Behaviours
State Machine Behaviours
In Unity 5, you’ll be able to add StateMachineBehaviour scripts to your states, and receive the following callbacks when the states are played:
在Unity 5中,可以在某些状态中添加StateMachineBehaviour脚本。某些状态出现时,将出现以下几种回调。
• OnStateEnter
• OnStateUpdate
• OnStateExit
• OnStateMove
• OnStateIK
You can have as many StateMachineBehaviours in your State as you like. So to add IK on State, or to do some custom logic, simply drag the StateMachineBehaviour script on to it.
只要我们喜欢,就可以在状态中添加很多StateMachineBehaviours脚本。因此,我们可以在状态中添加OnStateIK,或添加其他自定义逻辑脚本,或仅是把StateMachineBehaviour脚本粘上去。
Basically, anything that requires some kind of StateMachine logic in your game – with or without animation – can use this.
通常情况下,只要游戏中有需要一些StateMachine逻辑的地方,就可以使用StateMachineBehaviours脚本。
![](https://i-blog.csdnimg.cn/blog_migrate/05a2220e133dd3f8e301c740ab3b5a42.png)
Another great thing about this feature is that you don’t need to have tons of
State Machine Behaviours的另个特点是不用再写很多下述这些代码:
[C#] 纯文本查看 复制代码?
12 if(animator.GetCurrentAnimatorStateInfo(0).isName("Idle") ) DoStuff()
(which I’m sure you have plenty of in your code),
(我不确定你们是否要写很多类似这样的代码)
you can just use StateMachineBehaviours instead!
只需用StateMachineBehaviours替代下就行了。
State Machine Transitions
状态机转换
State Machines are growing more and more complex, so we introduced the concept of State Machine Transitions to provide a higher level of abstraction over the StateMachine logic.
因为状态机变得越来越复杂了。我打算介绍下状态机转换,它可在状态机逻辑之上提供给我们更高层次的抽象表示。
In Unity 5, we’ve added Entry and Exit nodes to StateMachines. There are used during State Machine Transitions.
在Unity 5中,我们已在状态机中添加进入和退出节点。这两种节点都在状态及转换中使用。
Entry: When you transition to a StateMachine, the animation system will evaluate the Entry node and branch to the destination that its conditions meet.
进入节点:进行状态机转换时,动画系统将计算进入节点和进入分支到目标节点需要满足的条件。
Exit: When going to the Exit node, the animation system will look at the outgoing StateMachine transitions and branch to the proper destination.
退出节点:到了退出节点时,动画系统将查看已运行的状态机转换并找出更合理的到终节点的路径。
Note that you can mix transitions: State->State, State->StateMachine, StateMachine->StateMachine…
我们可以添加这样的转换类型:State->State, State->StateMachine, StateMachine->StateMachine…
![](https://i-blog.csdnimg.cn/blog_migrate/d0477df3b86712945609244983e1cdb9.png)
What’s more, we also revamped the UI for our tool so you can now re-order your parameters and layers.
此外,我们还修改了用户工具。因此,可以重新命令参数和图层。
Asset Creation API
资源创建器接口
In Unity 5 you can create animation assets; StateMachines, States, Controllers, Layers, Blentrees, etc., using scripts in the Editor!
在Unity 5中,可以创建动画资源,例如:在编辑器中用脚本创建状态机,状态,控件,图层,树型结构等。
There are two APIs, a high-level one, where the assets are managed by Unity and a low level one where you manage assets manually, and can perform external referencing.
有两种API,一种是由Unity来管理资源的高级别API。另一种是设计者自行管理资源和执行外部引用操作的低级别API。
Both APIs are documented, and I’ve put a small example of API usage at the end of this post.
这两种API我已介绍了。接下来,我将在文章的最后,通过事例来说明API的使用。
Direct Blend Trees
直接混合树
We’ve added a new type of BlendTree that allows you to map an animator parameter to the weight of a BlendTree child directly.
我们已在混合树中添加了新属性,该属性可通过动画控制器参数直接设置混合树子树的权值。
![](https://i-blog.csdnimg.cn/blog_migrate/e9639978aa70e5424f26bcc8d727ce60.png)
This can come in really handy if you’re working with BlendShape animations, or additive animations.
这样一来,动画融合变形和动画叠加就容易操作了。
Root Motion Authoring (in generic mode)
根运动的创建(常规模式下)
Unity 5 also allows you to animate objects and convert their animator to root motion (ie Delta Animation). Simply create an animation – translation/rotation – on the topmost transform of an object then click Generate Root Motion Curve in the AnimationClip inspector!
Unity 5可以动画绘制物体和创建动画到根运动(比如Delta Animation)。只需创建动画,再转换/平移,然后最外层转换物体。最后在动画剪辑检视面板中单击Generate Root Motion Curve
More stuff that will make your life easier:
• Improved animation previewer camera. The camera can now Pan, Orbit and Scale in the same way as the scene viewer.
• Runtime access to parameters (name, default values etc..)
• Gizmo in scene view for root position, ik position, etc…
• Improved retargeting engine
• Runtime optimizations
• Tons and tons of bug fixes
更多功能,让动画制作更轻松:
• 改进动画预览器相机。现在,相机可以像场景浏览器一样进行平移,旋转和缩放。
• 运行时访问参数(如名称,默认值等)
• 为场景视图中的Gizmo根定位,ik定位等。
• 改进重新目标定位引擎
• 运行时自动优化
• 可以修复大量的错误
Let us know what you think of these changes!
The Animation Team.
告诉我们,你对这些新功能的看法。
我们是动画团队。
Asset Creation API sample Code
资源创建器的示例代码
// Creates the controller
var controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath ("Assets/Mecanim/StateMachineTransitions.controller");
// Add parameters
controller.AddParameter(“TransitionNow”, UnityEditor.Animations.AnimatorControllerParameterType.Trigger);
controller.AddParameter(“Reset”, UnityEditor.Animations.AnimatorControllerParameterType.Trigger);
controller.AddParameter(“GotoB1〃, UnityEditor.Animations.AnimatorControllerParameterType.Trigger);
controller.AddParameter(“GotoC”, UnityEditor.Animations.AnimatorControllerParameterType.Trigger);
// Add StateMachines
var rootStateMachine = controller.layers[0].stateMachine;
var stateMachineA = rootStateMachine.AddStateMachine(“smA”);
var stateMachineB = rootStateMachine.AddStateMachine(“smB”);
var stateMachineC = stateMachineB.AddStateMachine(“smC”);
// Add States
var stateA1 = stateMachineA.AddState(“stateA1〃);
var stateB1 = stateMachineB.AddState(“stateB1〃);
var stateB2 = stateMachineB.AddState(“stateB2〃);
stateMachineC.AddState(“stateC1〃);
var stateC2 = stateMachineC.AddState(“stateC2〃); // don’t add an entry transition, should entry to state by default
// Add Transitions
var exitTransition = stateA1.AddExitTransition();
exitTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “TransitionNow”);
exitTransition.duration = 0;
var resetTransition = stateMachineA.AddAnyStateTransition(stateA1);
resetTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “Reset”);
resetTransition.duration = 0;
var transitionB1 = stateMachineB.AddEntryTransition(stateB1);
transitionB1.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “GotoB1〃);
stateMachineB.AddEntryTransition(stateB2);
stateMachineC.defaultState = stateC2;
var exitTransitionC2 = stateC2.AddExitTransition();
exitTransitionC2.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “TransitionNow”);
exitTransitionC2.duration = 0;
var stateMachineTransition = rootStateMachine.AddStateMachineTransition(stateMachineA, stateMachineC);
stateMachineTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “GotoC”);
rootStateMachine.AddStateMachineTransition(stateMachineA, stateMachineB);