Animations 动画
Unity's Animation System allows you to create beautifully animated skinned characters. The Animation System supports animation blending, mixing, additive animations, walk cycle time synchronization, animation layers, control over all aspects of the animation playback (time, speed, blend-weights), mesh skinning with 1, 2 or 4 bones per vertex and finally physically based ragdolls.
Unity的动画系统允许你创建优美的动画角色。动画系统支持动画合成、混合、添加动画、步调周期时间同步、动画层、控制动画回放的所有方面(时间、速度、混合权重)、每个顶点有1、2、4个骨骼的网格蒙皮、以及最终基于物理的布娃娃系统。
There are some best practices for creating a rigged character with optimal performance in Unity. It is recommended that you read about these techniques on the Modeling Optimized Characters page.
有一些最佳方式来在Unity中创建一个最佳性能的角色。建议阅读角色建模优化。
If you like, quickly jump to one of the topics covered on this page:
如果你喜欢,快速跳转到本页所涵盖的某一个议题:
- Importing Character Animations 导入角色动画
- Animation Splitting 分割动画
- Multiple Files 多个文件
- Inverse Kinematics 反向动力学
- Inserting Into a Unity Scene 插入到Unity场景中
You can download an example demo showing pre-setup animated characters here.
你可以在这里下载一个例子演示显示预安装动画角色。
Importing The Animations 导入动画
First of all we have to import the character. Unity natively imports Maya (.mb or .ma) files, Cinema 4D (.c4d) files, and fbx files which can be exported from most animation packages. Click here to learn how to export from your modelling/animation package.
首先我们导入角色。Unity支持导入Maya(.mb或.ma)文件,Cinema 4D(.c4d)文件,和FBX文件,这些可从大多数动画包导出。点击这里了解如何从你的建模/动画包导出。
Importing Animations using Animation Splitting 使用动画分割导入动画
The most convenient way for animators to work is to have a single model containing all animations. When importing the animated model, you can define which frames make up each part of the animation. Unity will automatically split the animation into the individual parts, called Animation Clips.
最方便的制作动画的途径是有一个包含所有动画的单一模型。当导入该动画模型时,你可以定义每个动画的部分由哪些帧构成。Unity将把动画自动分割成独立的部分,称为动画剪辑。
For example 例如:
- walk animation during frames 1 - 33 行走动画在帧1-33
- run animation during frames 41 - 57 跑步动画在帧41-57
- kick animation during frames 81 - 97 踢腿动画在帧81-97
To import the animations you simply place the model in the Assets folder of your project. Unity will now automatically import it. Highlight it in the Project View and edit the Import Settings in the Inspector.
要导入动画你只需放置模型到项目的资源文件夹中,Unity将会自动导入。在项目视图中高亮它(选中它),并在检视视图中编辑导入设置。
The Import Settings Dialog for a mesh 一个网格的导入设置对话框
In the Import Settings, the Split Animations table is where you tell Unity which frames in your asset file make up which Animation Clip. The names you specify here are used to activate them in your game.
在导入设置中,拆分动画表是告诉Unity,资源文件的哪些帧构成动画的哪些片段。此处你指定的名称用来在游戏中起动它们。
- Name 名称 Defines the Animation Clip's name within Unity.
定义在Unity中动画片段的名称。 - start frame 起始帧 The first frame of the animation. The frame number refers to the same frame as in the 3D program used to create the animation.
动画的第一帧,帧编号是3D程序创建动画的同一帧。 - stop frame 终止帧 The last frame of the animation. 动画的最后一帧。
- WrapMode 循环模式 Defines how should time beyond the playback range of the clip be treated (Once, Loop, PingPong, ClampForever).
定义超出了片段播放范围的时间应该如何处理(一次、循环、往复、永久钳) - loop frame 循环帧 If enabled, an extra loop frame is inserted at the end of the animation. This frame matches the first frame in the clip. Use this if you want to make a looping animation and the first & last frames don't match up exactly.
如果启用,动画末尾将插入一个额外的循环帧,此帧和剪辑的第一帧相匹配。如果你想作一个循环动画并且第一帧和最后一帧不完全匹配时,使用它。
Importing Animations using multiple model files 使用多个模型文件导入动画
The other way to import animations is to follow the @ animation naming scheme. You create separate model files and use this naming convention: 'model name'@'animation name'.fbx
导入动画的另一种方法是在后面接"@"动画命名方案。你创建单独的模型文件,并使用这样的命名约定——"模型名称"@"动画名称".fbx
An example of four animation files for an animated character
具有4个动画文件的动画角色的例子
Unity automatically imports all four files and collects all animations to the file without the @ sign in. In the example above, the goober.mb file will be set up to reference idle, jump, walk and wallJump automatically.
Unity自动导入四个文件,并收集所有动画到没有@符号的文件。在上文的例子中,goober.mb文件将自动设置引用空闲、跳跃、走路和翻墙。
Importing Inverse Kinematics 导入反向动力学
When importing animated characters from Maya that are created using IK, you have to check the Bake IK & simulation box in the Import Settings. Otherwise, your character will not animate correctly.
当导入的动画角色是通过Maya使用IK(反向动力学,见上一节)创建的,你必须检查导入设置中的烘焙IK与仿真箱。否则,你的角色将不能正确动作。
Bringing the character into the Scene 导入角色到场景中
When you have imported your model you drag the object from the Project view into the Scene View or Hierarchy.
当你已经导入了模型,从项目视图中拖动对象到场景视图或层次视图中。
The animated character is added by dragging it into the scene
动画角色通过拖拽到场景来添加
The character above has three animations in the animation list and no default animation. You can add more animations to the character by dragging animation clips from the Project View on to the character (in either the Hierarchy or Scene View). This will also set the default animation. When you hit Play, the default animation will be played.
上文的角色在动画列表中有三个动画且没有默认动画。你可以添加更多的动画到角色上,通过从项目视图拖动动画片段到角色上(无论是在层次视图或场景视图)。这也将设置默认动画,当你点击播放,默认动画将运行。
TIP: You can use this to quickly test if your animation plays back correctly. Also use the Wrap Mode to view different behaviors of the animation, especially looping.
小提示:如果你的动画回放正确,你可以用它来快速测试。还可以使用循环模式查看动画的默认行为,尤其是循环。