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"));

}

创建浮点曲线

赋值曲线

效果:

相关推荐
MediaTea11 分钟前
Python 第三方库:Word Cloud(词云图生成)
开发语言·python
小龙报18 分钟前
《算法每日一题(1)--- 第31场蓝桥算法挑战赛》
c语言·开发语言·c++·git·算法·学习方法
llz_11219 分钟前
五子棋小游戏
开发语言·c++·算法
liulilittle21 分钟前
在 Android Shell 终端上直接运行 OPENPPP2 网关路由配置指南
android·linux·开发语言·网络·c++·编程语言·通信
lihongli00035 分钟前
ROS与Qt结合开发CAN控制界面(发布自定义的truck_send_can1消息)
开发语言·qt·ros
java1234_小锋44 分钟前
什么是Java三高架构?
java·开发语言·架构
如竟没有火炬1 小时前
全排列——交换的思想
开发语言·数据结构·python·算法·leetcode·深度优先
嵌入式小李.man1 小时前
C++第十三篇:继承
开发语言·c++
Bryce李小白1 小时前
Kotlin Flow 的使用
android·开发语言·kotlin
jarreyer2 小时前
python离线包安装方法总结
开发语言·python