Created
September 24, 2018 06:55
-
-
Save PaperSloth/3f3644565061b42b9c63a12785ee91bf to your computer and use it in GitHub Desktop.
UnrealC++でTimerを使用した処理の書き方
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright(c) 2018 PaperSloth | |
#include "ExampleActor.h" | |
#include "TimerManager.h" | |
AExampleActor::AExampleActor() | |
{ | |
} | |
void AExampleActor::BeginPlay() | |
{ | |
Super::BeginPlay(); | |
FTimerManager& timerManager = GetWorldTimerManager(); | |
// TimerFuncion登録 | |
timerManager.SetTimer(timerHandle, this, &AExampleActor::OnOutputLog, 0.2f, false); | |
// 引数付きTimerFuncion登録 | |
FTimerDelegate TimerDelegate; | |
TimerDelegate.BindUFunction(this, FName("InitializeTransform"), 100, FVector::ZeroVector, FQuat::Identity); | |
timerManager.SetTimer(argsTimerHandle, TimerDelegate, 0.3f, false); | |
// LambdaでのTimerFuncion登録 | |
timerManager.SetTimer(lambdaTimerHandle, []() | |
{ | |
UE_LOG(LogTemp, Error, TEXT("Call Lambda SetTimer")); | |
}, 0.5f, false | |
); | |
} | |
void AExampleActor::EndPlay(const EEndPlayReason::Type EndPlayReason) | |
{ | |
Super::EndPlay(EndPlayReason); | |
#if 0 | |
FTimerManager& timerManager = GetWorldTimerManager(); | |
// Handleに登録されたTimerの解放 | |
timerManager.ClearTimer(timerHandle); | |
timerManager.ClearTimer(argsTimerHandle); | |
timerManager.ClearTimer(lambdaTimerHandle); | |
#endif | |
// このActorが所有するタイマーの解放 | |
GetWorldTimerManager().ClearAllTimersForObject(this); | |
} | |
void AExampleActor::OnOutputLog() | |
{ | |
UE_LOG(LogTemp, Error, TEXT("Call SetTimer")); | |
} | |
void AExampleActor::InitializeTransform(const int32 Id, const FVector& Location, const FQuat& Quat) | |
{ | |
UE_LOG(LogTemp, Error, TEXT("Call Args SetTimer")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright(c) 2018 PaperSloth | |
#pragma once | |
#include "CoreMinimal.h" | |
#include "GameFramework/Actor.h" | |
#include "ExampleActor.generated.h" | |
UCLASS() | |
class CPPSANDBOX_API AExampleActor : public AActor | |
{ | |
GENERATED_BODY() | |
public: | |
AExampleActor(); | |
protected: | |
virtual void BeginPlay() override; | |
public: | |
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason); | |
private: | |
FTimerHandle timerHandle; | |
FTimerHandle argsTimerHandle; | |
FTimerHandle lambdaTimerHandle; | |
protected: | |
UFUNCTION() | |
void OnOutputLog(); | |
UFUNCTION() | |
void InitializeTransform(const int32 Id, const FVector& Location, const FQuat& Quat); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment