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

}

创建浮点曲线

赋值曲线

效果:

相关推荐
vortex51 分钟前
探索 Shell:选择适合你的命令行利器 bash, zsh, fish, dash, sh...
linux·开发语言·bash·shell·dash
zzc9214 分钟前
MATLAB仿真生成无线通信网络拓扑推理数据集
开发语言·网络·数据库·人工智能·python·深度学习·matlab
HUN金克斯13 分钟前
C++/C函数
c语言·开发语言·c++
慢半拍iii13 分钟前
数据结构——F/图
c语言·开发语言·数据结构·c++
钢铁男儿16 分钟前
C# 表达式和运算符(表达式和字面量)
开发语言·c#
编程有点难19 分钟前
Python训练打卡Day43
开发语言·python·深度学习
m0_6371469324 分钟前
零基础入门 C 语言基础知识(含面试题):结构体、联合体、枚举、链表、环形队列、指针全解析!
c语言·开发语言·链表
LjQ204033 分钟前
网络爬虫一课一得
开发语言·数据库·python·网络爬虫
你是狒狒吗40 分钟前
TM中,return new TransactionManagerImpl(raf, fc);为什么返回是new了一个新的实例
java·开发语言·数据库