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

}

创建浮点曲线

赋值曲线

效果:

相关推荐
longlongzihan2 分钟前
LeetCode 41. 缺失的第一个正数:从基础解法到原地哈希
c++·算法·leetcode
czq_268671948722 分钟前
Python打卡第34天
开发语言·python·机器学习
Lhan.zzZ38 分钟前
Qt/QML:业务记录单展示、签名确认与 PDF 导出开发
c++·qt·pdf
傲世仙尊40 分钟前
类和对象上-class与struct实例化内存对齐与this指针
c++
C++ 老炮儿的技术栈1 小时前
C++ const 的3个核心作用
服务器·c语言·c++·算法·c
小黄人软件1 小时前
粘贴助手C++版 支持 Windows 7 / 10 / 11 不会出现缺少api-ms-win-core-path-11-1-0.dll
开发语言·c++·windows
有毒的教程1 小时前
Dev-C++ 避免爆栈(Stack Overflow)完整方案
c++·算法·深度优先
半亩码田1 小时前
C#转Python第4.7篇:logging:Python 的标准日志库
开发语言·python·c#
程序员老陆1 小时前
从汇编层面理解 C++ 多线程
开发语言·c++·程序设计
谢亮_vipxieliang1 小时前
深入理解 JavaScript 数据类型与类型转换
开发语言·javascript·ecmascript