Version: 2017.4
Animation Curves on Imported Clips
Selecting a Root Motion Node

Animation events on imported clips

Animation events can be attached to imported animation clips in the Animations tab of the Animation Import Settings.

These events allow you to add additional data to an imported clip which determines when certain actions should occur in time with the animation. For example, for an animated character you might want to add events to walk and run cycles indicating when the footstep sounds should play.

To add an event to an imported animation, first select the imported animation file in your project view, then in the import settings in the inspector, select the Animations button.

View the Animations section of the Import Settings for your animation file
View the Animations section of the Import Settings for your animation file

Then scroll all the way to the bottom of the inspector to find the Events heading, among the four fold-out headings as shown:

The Events fold-out heading, along with the Curves, Masks, and Motion headings
The Events fold-out heading, along with the Curves, Masks, and Motion headings

Expand the events heading to reveal the events timeline for the current imported animation clip.

在任何事件被添加之前的 Events 时间轴
在任何事件被添加之前的 Events 时间轴

要将播放头移动到时间轴中的其他位置,请使用窗口预览面板中的时间轴:

Clicking in the preview pane timeline allows you to control where your new event will be created in the event timeline
Clicking in the preview pane timeline allows you to control where your new event will be created in the event timeline

Position the playback head at the point where you want to add an event, then click Add Event. A new event is created, indicated by a small white marker on the timeline. In the Function field, fill in the name of the function to call when the event is reached.

确保在其animator中使用此动画的任何游戏对象都附加了相应的脚本,其中包含具有匹配事件名称的函数。

下面的示例演示了一个事件会调用附加到玩家游戏对象的脚本中的 Footstep 函数。此事件可与音频源结合用于播放与动画同步的脚步声。

一个调用Footstep函数的事件
一个调用“Footstep”函数的事件

You can also choose to specify a parameter, which is sent to the function called by the event. There are four different parameter types: Float, Int, String or Object.

通过填写其中任何字段的值,并实现接受该类型参数的函数,即可将事件中指定的值传递给脚本中的函数。

例如,您可能希望传递 float(浮点)值来指定在不同动作期间应有的脚步声大小,例如在行走周期中采用安静脚步事件,而在奔跑循环中采用响亮脚步事件。此外,还可以传递对效果预制件的引用,从而让您的脚本在动画期间的特定时间点实例化不同的效果。

Animation Curves on Imported Clips
Selecting a Root Motion Node