UE5 C++ TimeLine 时间轴练习

一. Actor引入头文件

#include "Components/TimelineComponent.h"

声明CurveFloat 和 TimelineComponent

	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中构造函数里创建组件

MyTimeline = CreateDefaultSubobject<UTimelineComponent>(TEXT("MyTimeLineComponent")); 

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

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


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

将代理完成

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. TCP协议是安全的吗?

    2024-04-20 18:52:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-20 18:52:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-20 18:52:04       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-20 18:52:04       20 阅读

热门阅读

  1. Git常用命令

    2024-04-20 18:52:04       12 阅读
  2. Hive:日期函数

    2024-04-20 18:52:04       13 阅读
  3. IP地址和物理地址的理解

    2024-04-20 18:52:04       13 阅读
  4. 匿名函数lambda

    2024-04-20 18:52:04       15 阅读
  5. Python的pytest框架(2)--断言机制

    2024-04-20 18:52:04       15 阅读
  6. 进程和线程的区别和联系

    2024-04-20 18:52:04       13 阅读
  7. 浏览器——Microsoft Edge

    2024-04-20 18:52:04       14 阅读
  8. 【Windows】GPU、CUDA、cuDNN、Pytorch、Python知识总结

    2024-04-20 18:52:04       12 阅读