一. 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"));
}
创建浮点曲线
赋值曲线
效果: