UE5 C++ TimeLine 时间轴练习

一. Actor引入头文件

cpp 复制代码
#include "Components/TimelineComponent.h"

声明CurveFloat 和 TimelineComponent

cpp 复制代码
	UPROPERTY(EditAnywhere,BlueprintReadWrite,Category = "MyCurve")
	UCurveFloat* MyCurveFloat;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyCurve")
	UTimelineComponent* MyTimeline;

	FOnTimelineFloat TimelineDelegate;
	FOnTimelineEvent TimelineFinishedDelegate;
	UFUNCTION()
	void TimelineStart(float value);

二.Timeline 逻辑

TimelineActor中构造函数里创建组件

cpp 复制代码
MyTimeline = CreateDefaultSubobject<UTimelineComponent>(TEXT("MyTimeLineComponent")); 

绑定一个时间轴执行时事件,一个时间轴完成事件。

设置浮点曲线,设置数组循环(不循环)。

cpp 复制代码
	Super::BeginPlay();
	TimelineDelegate.BindUFunction(this,TEXT("TimelineStart"));   //dailiyoucanshu
	TimelineFinishedDelegate.BindUFunction(this,TEXT("TimelineFinished"));
	MyTimeline->AddInterpFloat(MyCurveFloat,TimelineDelegate);
	MyTimeline->SetLooping(false);
	MyTimeline->PlayFromStart();
	//MyTimeline->Play();
	MyTimeline->SetTimelineFinishedFunc(TimelineFinishedDelegate);   //

将代理完成

cpp 复制代码
void AMyTimeLineActor::TimelineStart(float value)
{
	GEngine->AddOnScreenDebugMessage(-1,5.0f,FColor::Red,FString::Printf(TEXT("Timelineplay %f"),value));
	float YawRotation = FMath::Lerp(0,90,value);
	MyDoorMesh->SetRelativeRotation(FRotator(0,YawRotation,0));
}

void AMyTimeLineActor::TimelineFinished()
{
	GEngine->AddOnScreenDebugMessage(-1,5.0f,FColor::Red,TEXT("TimelineFinshed"));

}

创建浮点曲线

赋值曲线

效果:

相关推荐
感哥40 分钟前
C++ 多重继承
c++
博笙困了1 小时前
C++提高编程 4.0
c++
扑克中的黑桃A1 小时前
[C语言]第三章-数据类型&变量
c++
感哥2 小时前
C++ std::string
c++
感哥18 小时前
C++ 面向对象
c++
沐怡旸20 小时前
【底层机制】std::shared_ptr解决的痛点?是什么?如何实现?如何正确用?
c++·面试
感哥1 天前
C++ STL 常用算法
c++
saltymilk2 天前
C++ 模板参数推导问题小记(模板类的模板构造函数)
c++·模板元编程
感哥2 天前
C++ lambda 匿名函数
c++
沐怡旸2 天前
【底层机制】std::unique_ptr 解决的痛点?是什么?如何实现?怎么正确使用?
c++·面试