RealtimeStyleTransferRuntime/Source/LyraGame/Character/LyraPawnExtensionComponent.h

107 lines
4.5 KiB
C
Raw Permalink Normal View History

2022-05-23 18:41:30 +00:00
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
2022-09-13 07:18:28 +00:00
#include "Components/GameFrameworkInitStateInterface.h"
#include "Components/PawnComponent.h"
#include "Delegates/Delegate.h"
#include "Engine/EngineTypes.h"
#include "GameFramework/Actor.h"
#include "Templates/Casts.h"
#include "UObject/NameTypes.h"
#include "UObject/UObjectGlobals.h"
2022-05-23 18:41:30 +00:00
2022-09-13 07:18:28 +00:00
#include "LyraPawnExtensionComponent.generated.h"
2022-05-23 18:41:30 +00:00
2022-09-13 07:18:28 +00:00
class UGameFrameworkComponentManager;
2022-05-23 18:41:30 +00:00
class ULyraAbilitySystemComponent;
2022-09-13 07:18:28 +00:00
class ULyraPawnData;
class UObject;
struct FActorInitStateChangedParams;
struct FFrame;
struct FGameplayTag;
2022-05-23 18:41:30 +00:00
/**
2022-09-13 07:18:28 +00:00
* Component that adds functionality to all Pawn classes so it can be used for characters/vehicles/etc.
* This coordinates the initialization of other components.
2022-05-23 18:41:30 +00:00
*/
UCLASS()
2022-09-13 07:18:28 +00:00
class LYRAGAME_API ULyraPawnExtensionComponent : public UPawnComponent, public IGameFrameworkInitStateInterface
2022-05-23 18:41:30 +00:00
{
GENERATED_BODY()
public:
ULyraPawnExtensionComponent(const FObjectInitializer& ObjectInitializer);
2022-09-13 07:18:28 +00:00
/** The name of this overall feature, this one depends on the other named component features */
static const FName NAME_ActorFeatureName;
//~ Begin IGameFrameworkInitStateInterface interface
virtual FName GetFeatureName() const override { return NAME_ActorFeatureName; }
virtual bool CanChangeInitState(UGameFrameworkComponentManager* Manager, FGameplayTag CurrentState, FGameplayTag DesiredState) const override;
virtual void HandleChangeInitState(UGameFrameworkComponentManager* Manager, FGameplayTag CurrentState, FGameplayTag DesiredState) override;
virtual void OnActorInitStateChanged(const FActorInitStateChangedParams& Params) override;
virtual void CheckDefaultInitialization() override;
//~ End IGameFrameworkInitStateInterface interface
/** Returns the pawn extension component if one exists on the specified actor. */
2022-05-23 18:41:30 +00:00
UFUNCTION(BlueprintPure, Category = "Lyra|Pawn")
static ULyraPawnExtensionComponent* FindPawnExtensionComponent(const AActor* Actor) { return (Actor ? Actor->FindComponentByClass<ULyraPawnExtensionComponent>() : nullptr); }
2022-09-13 07:18:28 +00:00
/** Gets the pawn data, which is used to specify pawn properties in data */
2022-05-23 18:41:30 +00:00
template <class T>
const T* GetPawnData() const { return Cast<T>(PawnData); }
2022-09-13 07:18:28 +00:00
/** Sets the current pawn data */
2022-05-23 18:41:30 +00:00
void SetPawnData(const ULyraPawnData* InPawnData);
2022-09-13 07:18:28 +00:00
/** Gets the current ability system component, which may be owned by a different actor */
2022-05-23 18:41:30 +00:00
UFUNCTION(BlueprintPure, Category = "Lyra|Pawn")
ULyraAbilitySystemComponent* GetLyraAbilitySystemComponent() const { return AbilitySystemComponent; }
2022-09-13 07:18:28 +00:00
/** Should be called by the owning pawn to become the avatar of the ability system. */
2022-05-23 18:41:30 +00:00
void InitializeAbilitySystem(ULyraAbilitySystemComponent* InASC, AActor* InOwnerActor);
2022-09-13 07:18:28 +00:00
/** Should be called by the owning pawn to remove itself as the avatar of the ability system. */
2022-05-23 18:41:30 +00:00
void UninitializeAbilitySystem();
2022-09-13 07:18:28 +00:00
/** Should be called by the owning pawn when the pawn's controller changes. */
2022-05-23 18:41:30 +00:00
void HandleControllerChanged();
2022-09-13 07:18:28 +00:00
/** Should be called by the owning pawn when the player state has been replicated. */
2022-05-23 18:41:30 +00:00
void HandlePlayerStateReplicated();
2022-09-13 07:18:28 +00:00
/** Should be called by the owning pawn when the input component is setup. */
2022-05-23 18:41:30 +00:00
void SetupPlayerInputComponent();
2022-09-13 07:18:28 +00:00
/** Register with the OnAbilitySystemInitialized delegate and broadcast if our pawn has been registered with the ability system component */
2022-05-23 18:41:30 +00:00
void OnAbilitySystemInitialized_RegisterAndCall(FSimpleMulticastDelegate::FDelegate Delegate);
2022-09-13 07:18:28 +00:00
/** Register with the OnAbilitySystemUninitialized delegate fired when our pawn is removed as the ability system's avatar actor */
2022-05-23 18:41:30 +00:00
void OnAbilitySystemUninitialized_Register(FSimpleMulticastDelegate::FDelegate Delegate);
protected:
virtual void OnRegister() override;
2022-09-13 07:18:28 +00:00
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
2022-05-23 18:41:30 +00:00
UFUNCTION()
void OnRep_PawnData();
2022-09-13 07:18:28 +00:00
/** Delegate fired when our pawn becomes the ability system's avatar actor */
2022-05-23 18:41:30 +00:00
FSimpleMulticastDelegate OnAbilitySystemInitialized;
2022-09-13 07:18:28 +00:00
/** Delegate fired when our pawn is removed as the ability system's avatar actor */
2022-05-23 18:41:30 +00:00
FSimpleMulticastDelegate OnAbilitySystemUninitialized;
2022-09-13 07:18:28 +00:00
/** Pawn data used to create the pawn. Specified from a spawn function or on a placed instance. */
2022-05-23 18:41:30 +00:00
UPROPERTY(EditInstanceOnly, ReplicatedUsing = OnRep_PawnData, Category = "Lyra|Pawn")
2022-09-13 07:18:28 +00:00
TObjectPtr<const ULyraPawnData> PawnData;
2022-05-23 18:41:30 +00:00
2022-09-13 07:18:28 +00:00
/** Pointer to the ability system component that is cached for convenience. */
2022-05-23 18:41:30 +00:00
UPROPERTY()
2022-09-13 07:18:28 +00:00
TObjectPtr<ULyraAbilitySystemComponent> AbilitySystemComponent;
2022-05-23 18:41:30 +00:00
};