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

}

创建浮点曲线

赋值曲线

效果:

相关推荐
一只小小的芙厨1 天前
寒假集训笔记·树上背包
c++·笔记·算法·动态规划
马猴烧酒.1 天前
【面试八股|Java集合】Java集合常考面试题详解
java·开发语言·python·面试·八股
以卿a1 天前
C++(继承)
开发语言·c++·算法
lly2024061 天前
XQuery 选择和过滤
开发语言
测试工程师成长之路1 天前
Serenity BDD 框架:Java + Selenium 全面指南(2026 最新)
java·开发语言·selenium
czxyvX1 天前
017-AVL树(C++实现)
开发语言·数据结构·c++
你真是饿了1 天前
1.C++入门基础
开发语言·c++
天天进步20151 天前
Python全栈项目:实时数据处理平台
开发语言·python
Tipriest_1 天前
Python中is关键字详细说明,比较的是地址还是值
开发语言·python
sheji34161 天前
【开题答辩全过程】以 基于Python的餐饮统计系统的设计和实 现为例,包含答辩的问题和答案
开发语言·python