Files
TerracottaWarriors/Plugins/ObjectPool/Source/OBJPool/Public/PooledPawn.h
2025-07-14 22:24:27 +08:00

97 lines
4.6 KiB
C++

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
/// Copyright 2019 (C) Bruno Xavier B. Leite
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "PoolSpawnOptions.h"
#include "Runtime/Engine/Public/TimerManager.h"
#include "Runtime/Engine/Classes/GameFramework/Pawn.h"
#include "PooledPawn.generated.h"
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class UPawnPool;
class UPooledProjectile;
class USharedObjectPool;
class UPooledSplineProjectile;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Pooled Pawn:: Pawn Class Template
/// Pooled Object Template;
/// Pawn type capable of being spawned as member of a Pool and automatically managed by the Pool Component.
UCLASS(ClassGroup = Synaptech, Category = "Performance", Blueprintable, BlueprintType, meta = (DisplayName = "Pool Pawn", ShortTooltip = "Pool Pawn Class. Check documentation for more information."))
class OBJPOOL_API APooledPawn : public APawn {
GENERATED_UCLASS_BODY()
//
friend class UPawnPool;
friend class UPooledProjectile;
friend class USharedObjectPool;
friend class UPooledSplineProjectile;
private:
UPROPERTY()
UPawnPool* OwningPool;
//
UPROPERTY()
FTimerHandle LifeSpanHandle;
protected:
UPROPERTY(Category="Object Pool", BlueprintReadOnly)
bool Spawned;
protected:
/// Finishes Spawning this Pawn, after deferred spawning from the Object-Pool.
virtual void FinishSpawnFromPool(const bool Reconstruct, const FTransform &Transform);
public:
virtual void Initialize();
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
//
/// How long this Pawn lives after Spawn from Pool. 0 = Forever.
UPROPERTY(Category = "Object Pool", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0"))
float LifeSpanPool;
//
//
UFUNCTION()
void SpawnFromPool(const bool Reconstruct, const FPoolSpawnOptions &SpawnOptions, const FTransform &SpawnTransform);
//
/// Returns this Pooled Pawn to its owning Object-Pool, disabling it.
UFUNCTION(Category = "Object Pool", BlueprintCallable, meta = (DisplayName = "Return to Pool", Keywords = "return character pool"))
void ReturnToPool();
//
/// Returns reference to the Pool Component owner of this Pawn.
UFUNCTION(Category = "Object Pool", BlueprintCallable, meta = (DisplayName = "Get Owning Pool", Keywords = "get owner pool"))
UPawnPool* GetOwningPool() const;
//
//
/// Sets Pawn's Life Span from Pool. When it expires the object will be destroyed. If requested lifespan is 0, the timer is cleared and the actor will not be destroyed.
UFUNCTION(Category = "Object Pool", BlueprintCallable, meta = (Keywords = "get life span"))
virtual void SetLifeSpanPool(float InLifespan);
//
/// Gets Pawn's remaining Life Span from Pool. If zero is returned the actor lives forever.
UFUNCTION(Category = "Object Pool", BlueprintCallable, meta = (Keywords = "get life span"))
virtual float GetLifeSpanPool() const;
//
//
/// Event called every time this Pawn is spawned from the Pool.
UPROPERTY(Category = "Object Pool", BlueprintAssignable)
FOBJP_PoolEvent OnPoolBeginPlay;
//
/// Event called every time this Pawn is sent back to the Pool.
UPROPERTY(Category = "Object Pool", BlueprintAssignable)
FOBJP_PoolEvent OnPoolEndPlay;
//
/// Event called every time this Pawn is spawned from the Pool.
UFUNCTION(Category = "Object Pool", BlueprintNativeEvent, meta = (DisplayName = "On Pool Begin Play", Keywords = "pool begin play event"))
void EVENT_OnPoolBeginPlay();
//
/// Event called every time this Pawn is sent back to the Pool.
UFUNCTION(Category = "Object Pool", BlueprintNativeEvent, meta = (DisplayName = "On Pool End Play", Keywords = "pool end play event"))
void EVENT_OnPoolEndPlay();
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////