TimeLine
-
首先在.h文件中创建时间轴组件
-
需要包含
#include "Components/BoxComponent.h"
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Timeline) UTimelineComponent* DoorTimeline;
-
创建UCurveFloat(时间轴曲线)和时间轴更新函数
-
public: // 用于保留曲线资产的变量 UPROPERTY(EditAnywhere) UCurveFloat* DoorTimelineFloatCurve; private: //用于处理我们的更新轨道事件的浮点轨道签名 FOnTimelineFloat UpdateFunctionFloat; //用于使用时间轴图表更新门相对位置的函数 UFUNCTION() void UpdateTimelineComp(float Output);
-
-
.cpp文件中实现
-
void ADoor::UpdateTimeline(float Output) { // 基于时间轴曲线的输出创建并设置门的新相对位置 FRotator DoorNewRotation = FRotator(0.0f, Output, 0.f); Door->SetRelativeRotation(DoorNewRotation); }
-
-
在BeginPlay中绑定