栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

UE4 C++ Timeline

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

UE4 C++ Timeline

UE4 C++ Timeline
我命名有点不规范注意点看

结束事件绑定
每次更改绑定

调用时间轴开始方法方法
1.先建C++类,用碰撞触发时间轴

代码

.h
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/BoxComponent.h"
#include "Components/TimelineComponent.h"
#include "GameFramework/Actor.h"
#include "Door.generated.h"

UCLASS()
class QWE_API ADoor : public AActor
{
	GENERATED_BODY()

public:
	UPROPERTY(VisibleAnywhere)
	USceneComponent* SceneComponent;

	UPROPERTY(VisibleAnywhere)
	UStaticMeshComponent* Door;

	UPROPERTY(VisibleAnywhere)
	UStaticMeshComponent* DoorClient;

	UPROPERTY(VisibleAnywhere)
	UBoxComponent* BoxComponent;

	UPROPERTY(VisibleAnywhere)
	UTimelineComponent* DoorTimeline;

	UPROPERTY(EditAnywhere)
	UCurveFloat* DoorTimelineFloatCurve;

	
	
	
public:	
	// Sets default values for this actors properties
	ADoor();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UFUNCTION()
	void BeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);

	UFUNCTION()
	void UpdateTimelineComp(float Output);

	UFUNCTION()
	void OnTimelineTick(float Output);
};



.CPP
// Fill out your copyright notice in the Description page of Project Settings.


#include "Actor/Door.h"

// Sets default values
ADoor::ADoor()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;
	SceneComponent=CreateDefaultSubobject(TEXT("SceneComponent"));
	RootComponent=SceneComponent;

	Door=CreateDefaultSubobject(TEXT("Door"));
	Door->SetupAttachment(SceneComponent);
	
	DoorClient=CreateDefaultSubobject(TEXT("DoorClient"));
	DoorClient->SetupAttachment(Door);

	BoxComponent=CreateDefaultSubobject(TEXT("BoxComponent"));
	BoxComponent->SetupAttachment(SceneComponent);

	DoorTimeline=CreateDefaultSubobject(TEXT("DoorTimeline"));
}

// Called when the game starts or when spawned
void ADoor::BeginPlay()
{
	Super::BeginPlay();
	BoxComponent->OnComponentBeginOverlap.AddDynamic(this,&ADoor::BeginOverlap);
	

	if (DoorTimelineFloatCurve!=nullptr)
	{
		FOnTimelineFloat TimelineEvent;
		FOnTimelineEventStatic TimelineEventend;
		TimelineEvent.BindUFunction(this,TEXT("OnTimelineTick"));
		TimelineEventend.BindUFunction(this,TEXT("UpdateTimelineComp"));
		DoorTimeline->AddInterpFloat(DoorTimelineFloatCurve,TimelineEvent);
		
		DoorTimeline->SetTimelineFinishedFunc(TimelineEventend);//完成时调用
		
		DoorTimeline->SetTimelineLengthMode(ETimelineLengthMode::TL_LastKeyFrame);//设置结束为最后一个帧
	}
	

	
}

// Called every frame
void ADoor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

void ADoor::BeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
	int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	if (DoorTimelineFloatCurve!=nullptr)
	{
		DoorTimeline->PlayFromStart();
	}
	
	UE_LOG(LogTemp,Warning,TEXT("Conlor"));
}

void ADoor::UpdateTimelineComp(float Output)
{
	UE_LOG(LogTemp,Warning,TEXT("wang cheng"));
}

void ADoor::OnTimelineTick(const float Output)
{
	UE_LOG(LogTemp,Warning,TEXT("%f"),Output);
}



**

设置时间轴曲线:

**

运行结果:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/968928.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号