曲线(Curve)(UCurveBase)定义了要在给定范围内求值的内插点的轨道。 曲线可以是向量、浮点以及颜色。 所有轨道都可以有任意数量的关键点,用于定义时间或值。 数据可以内插到这些关键帧之间,以计算时间轴中任何点的值。
使用关键帧和曲线
在本例中,你将创建一个UCurveFloat,它会定义要在给定范围内求值的内插浮点的曲线。
要创建UCurveFloat
并将其实例化为时间轴组件,请执行以下步骤:
找到内容浏览器,点击C++ Classes文件夹,然后点击添加(+)(Add (+))按钮并选择新建C++类(New C++ Class)。
选择Actor作为父类。
将创建的Actor命名为ExampleTimelineComponent。
创建新的Actor时,Visual Studio会自动打开
ExampleTimelineComponent.h
和ExampleTimelineComponent.cpp
文件。 找到ExampleTimelineComponent.h
文件并将以下内容添加到#include
分段中:ExampleTimelineComponent.h
C++#include "Components/TimelineComponent.h"
接下来,在
ExampleTimelineComponent
类定义中添加以下代码:ExampleTimelineComponent.h
C++protected: UPROPERTY(EditAnywhere, BlueprintReadWrite) UTimelineComponent* ExampleTimelineComp; public: UPROPERTY(EditAnywhere) UCurveFloat* ExampleTimelineCurve;
编译你的代码。
找到内容浏览器,选择添加(+)(Add (+))> 杂项(Miscellaneous)> 曲线(Curve)。
选择CurveFloat并将其命名为ExampleFloatTrack。
在内容浏览器中,找到包含你的ExampleTimelineComponent类的文件夹,右键点击并选择基于ExampleTimelineComponent创建蓝图类(Create Blueprint Class based on ExampleTimelineComponent)。 将其命名为BP_ExampleTimelineComponent。
打开BP_ExampleTimelineComponent类的默认值,找到细节(Detail)面板并分配带有ExampleFloatTrack的示例时间轴曲线。
在内容浏览器中,双击你的浮点轨道示例,并打开时间轴编辑器。
添加关键帧
添加关键点的方式是按下Enter键,或右键点击灰色条并从上下文菜单选择操作添加关键点(Add Key)。
编辑关键帧
要设置关键帧的时间和值,可点击该关键帧,在靠近轨道顶部的时间和值字段中输入值。
删除关键帧
若要删除所选关键点,按键盘上的Delete键,或右键点击你想删除的关键点,并从上下文菜单中选择删除(Delete)操作即可。
移动关键帧
要将关键帧沿着时间轴移动,选择该关键帧并拖动它。 若要选择多个关键点,请使用Ctrl键。 水平方向拖动可以更新该关键点的时间(Time)值,垂直拖动则更新值(Value)。
关键帧插值
右键点击关键帧,将显示上下文菜单,用于选择所选关键帧的插值类型。
关键帧插值仅影响内插的目标关键帧与其下一个关键帧之间的曲线。 例如,将所有其他关键点设为线性(Linear),中央关键点设为立方体自动(Cubic-Auto),则轨道将类似于下图。
可用插值类型有:
自动(Auto)
用户(User)
断裂(Break)
线性(Linear)
常量(Constant)