20. Constructing the ASC and AS

This commit is contained in:
Edward R. Gonzalez 2024-04-13 11:09:22 -04:00
parent 70d51d869c
commit f43daaed61
10 changed files with 99 additions and 2 deletions

Binary file not shown.

View File

@ -0,0 +1,4 @@
#pragma once
#include "GasaCommon.h"

View File

@ -1,12 +1,29 @@
#pragma once #pragma once
#include "AbilitySystemComponent.h" #include "AbilitySystemComponent.h"
#include "AbilitySystemInterface.h"
#include "GasaCommon.h"
#include "GasaAbilitySystemComponent.generated.h" #include "GasaAbilitySystemComponent.generated.h"
UCLASS() UCLASS()
class GASA_API UGasaAbilitySystemComp : public UAbilitySystemComponent class GASA_API UGasaAbilitySystemComp : public UAbilitySystemComponent
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
}; };
namespace Gasa
{
inline
UGasaAbilitySystemComp* GetAbilitySystem(UObject* Object)
{
if (Object->Implements<UAbilitySystemInterface>())
{
return Cast<UGasaAbilitySystemComp>( Cast<IAbilitySystemInterface>(Object)->GetAbilitySystemComponent() );
}
return nullptr;
}
}

View File

@ -1,12 +1,15 @@
#include "GasaCharacter.h" #include "GasaCharacter.h"
#include "Game/GasaLevelScriptActor.h" #include "AbilitySystemComponent.h"
#include "Camera/CameraComponent.h" #include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h" #include "Components/CapsuleComponent.h"
#include "GameFramework/CharacterMovementComponent.h" #include "GameFramework/CharacterMovementComponent.h"
#include "GameFramework/SpringArmComponent.h" #include "GameFramework/SpringArmComponent.h"
#include "Kismet/KismetSystemLibrary.h" #include "Kismet/KismetSystemLibrary.h"
#include "AbilitySystem/GasaAbilitySystemComponent.h"
#include "Game/GasaLevelScriptActor.h"
void AGasaCharacter::SetHighlight(EHighlight Desired) void AGasaCharacter::SetHighlight(EHighlight Desired)
{ {
HighlightState = Desired; HighlightState = Desired;
@ -35,6 +38,14 @@ AGasaCharacter::AGasaCharacter()
Weapon = CreateDefaultSubobject<USkeletalMeshComponent>("Weapon"); Weapon = CreateDefaultSubobject<USkeletalMeshComponent>("Weapon");
Weapon->SetupAttachment(mesh, FName("WeaponAttach")); Weapon->SetupAttachment(mesh, FName("WeaponAttach"));
Weapon->SetCollisionEnabled(ECollisionEnabled::NoCollision); Weapon->SetCollisionEnabled(ECollisionEnabled::NoCollision);
if (bAutoAbilitySystem)
{
AbilitySystem = CreateDefaultSubobject<UGasaAbilitySystemComp>("Ability System");
AbilitySystem->SetIsReplicated(true);
Attributes = CreateDefaultSubobject<UAttributeSet>("Attributes");
}
} }
void AGasaCharacter::BeginPlay() void AGasaCharacter::BeginPlay()

View File

@ -1,8 +1,10 @@
#pragma once #pragma once
#include "GasaCommon.h" #include "AbilitySystemInterface.h"
#include "GameFramework/Character.h" #include "GameFramework/Character.h"
#include "GasaCommon.h"
#include "GasaCharacter.generated.h" #include "GasaCharacter.generated.h"
UENUM(BlueprintType) UENUM(BlueprintType)
@ -14,9 +16,21 @@ enum class EHighlight : uint8
UCLASS(Abstract) UCLASS(Abstract)
class GASA_API AGasaCharacter : public ACharacter class GASA_API AGasaCharacter : public ACharacter
, public IAbilitySystemInterface
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
#pragma region Ability System
UPROPERTY(EditAnywhere, Category="Ability System")
bool bAutoAbilitySystem = true;
UPROPERTY(EditAnywhere, Category="Ability System")
TObjectPtr<UAbilitySystemComponent> AbilitySystem;
UPROPERTY(EditAnywhere, Category="Ability System")
TObjectPtr<UAttributeSet> Attributes;
#pragma endregion Ability System
#pragma region Combat #pragma region Combat
UPROPERTY(EditAnywhere, Category="Combat") UPROPERTY(EditAnywhere, Category="Combat")
TObjectPtr<USkeletalMeshComponent> Weapon; TObjectPtr<USkeletalMeshComponent> Weapon;
@ -42,6 +56,11 @@ public:
#pragma endregion Highlighting #pragma endregion Highlighting
AGasaCharacter(); AGasaCharacter();
#pragma region IAbilitySystem
FORCEINLINE UAttributeSet* GetAttributes() { return Attributes; }
FORCEINLINE UAbilitySystemComponent* GetAbilitySystemComponent() const override { return AbilitySystem; }
#pragma endregion IAbilitySystem
#pragma region Actor #pragma region Actor
void BeginPlay() override; void BeginPlay() override;
@ -49,3 +68,11 @@ public:
void Tick(float DeltaSeconds) override; void Tick(float DeltaSeconds) override;
#pragma endregion Actor #pragma endregion Actor
}; };
namespace Gasa
{
// UGasaAbilitySystemComp* GetAbilitySystem(AGasaCharacter* Object)
// {
//
// }
}

View File

@ -3,4 +3,6 @@
APlayerCharacter::APlayerCharacter() APlayerCharacter::APlayerCharacter()
{ {
PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.bCanEverTick = true;
bAutoAbilitySystem = false;
} }

View File

@ -1,7 +1,14 @@
#include "GasaPlayerState.h" #include "GasaPlayerState.h"
#include "AbilitySystem/GasaAbilitySystemComponent.h"
AGasaPlayerState::AGasaPlayerState() AGasaPlayerState::AGasaPlayerState()
{ {
AbilitySystem = CreateDefaultSubobject<UGasaAbilitySystemComp>("Ability System");
AbilitySystem->SetIsReplicated(true);
Attributes = CreateDefaultSubobject<UAttributeSet>("Attributes");
// Replication // Replication
NetUpdateFrequency = 100.f; NetUpdateFrequency = 100.f;
} }

View File

@ -1,13 +1,34 @@
#pragma once #pragma once
#include "AbilitySystemInterface.h"
#include "GameFramework/PlayerState.h" #include "GameFramework/PlayerState.h"
#include "GasaCommon.h"
#include "GasaPlayerState.generated.h" #include "GasaPlayerState.generated.h"
UCLASS(Blueprintable) UCLASS(Blueprintable)
class GASA_API AGasaPlayerState : public APlayerState class GASA_API AGasaPlayerState : public APlayerState
, public IAbilitySystemInterface
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
#pragma region Ability System
UPROPERTY(EditAnywhere, Category="Ability System")
bool bAutoAbilitySystem = true;
UPROPERTY(EditAnywhere, Category="Ability System")
TObjectPtr<UAbilitySystemComponent> AbilitySystem;
UPROPERTY(EditAnywhere, Category="Ability System")
TObjectPtr<UAttributeSet> Attributes;
#pragma endregion Ability System
AGasaPlayerState(); AGasaPlayerState();
#pragma region IAbilitySystem
FORCEINLINE UAttributeSet* GetAttributes() { return Attributes; }
FORCEINLINE UAbilitySystemComponent* GetAbilitySystemComponent() const override { return AbilitySystem; }
#pragma endregion IAbilitySystem
}; };

View File

@ -11,6 +11,11 @@
#pragma region Engine Forwards #pragma region Engine Forwards
struct FInputActionValue; struct FInputActionValue;
class IAbilitySystemInterface;
class UAbilitySystemComponent;
class UAbilitySystemInterface;
class UAttributeSet;
class UCameraComponent; class UCameraComponent;
class UInputAction; class UInputAction;
class UInputMappingContext; class UInputMappingContext;
@ -31,9 +36,11 @@ class AGasaGameState;
class AGasaLevelScriptActor; class AGasaLevelScriptActor;
class AGasaPlayerController; class AGasaPlayerController;
class UGasaAbilitySystemComp;
class UGasaDevOptions; class UGasaDevOptions;
#pragma endregion Forwards #pragma endregion Forwards
#pragma region Logging
// Straight from the Engine // Straight from the Engine
UENUM(BlueprintType) UENUM(BlueprintType)
enum class EGasaVerbosity : uint8 enum class EGasaVerbosity : uint8
@ -122,3 +129,4 @@ namespace Gasa
#define GASA_Log(Message) UE_LOG( Gasa, Log, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() ); #define GASA_Log(Message) UE_LOG( Gasa, Log, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() );
#define GASA_Verbose(Message) UE_LOG( Gasa, Verbose, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() ); #define GASA_Verbose(Message) UE_LOG( Gasa, Verbose, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() );
#define GASA_VeryVerbose(Message) UE_LOG( Gasa, VeryVerbose, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() ); #define GASA_VeryVerbose(Message) UE_LOG( Gasa, VeryVerbose, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() );
#pragma endregion Logging