第一次提交
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "AbilitySystemGlobals.h"
|
||||
#include "GGA_AbilitySystemStructLibrary.h"
|
||||
#include "GGA_AbilitySystemGlobals.generated.h"
|
||||
|
||||
class IGGA_AbilitySystemGlobalsEventReceiver;
|
||||
|
||||
/**
|
||||
* Extended ability system globals for custom functionality.
|
||||
* 扩展的技能系统全局类,提供自定义功能。
|
||||
*/
|
||||
UCLASS()
|
||||
class GENERICGAMEPLAYABILITIES_API UGGA_AbilitySystemGlobals : public UAbilitySystemGlobals
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
/**
|
||||
* Processes gameplay effect specs before application.
|
||||
* 在应用游戏效果规格前进行处理。
|
||||
* @param Spec The gameplay effect spec. 游戏效果规格。
|
||||
* @param AbilitySystemComponent The ability system component. 技能系统组件。
|
||||
*/
|
||||
virtual void GlobalPreGameplayEffectSpecApply(FGameplayEffectSpec& Spec, UAbilitySystemComponent* AbilitySystemComponent) override;
|
||||
|
||||
/**
|
||||
* Allocate a GGA_GameplayEffectContext struct. Caller is responsible for deallocation
|
||||
* 分配一个GGA_GameplayEffectContext.
|
||||
*/
|
||||
virtual FGameplayEffectContext* AllocGameplayEffectContext() const override;
|
||||
|
||||
/**
|
||||
* Retrieves the ability system globals instance.
|
||||
* 获取技能系统全局实例。
|
||||
* @return The ability system globals instance. 技能系统全局实例。
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|Globals")
|
||||
static const UAbilitySystemGlobals* GetAbilitySystemGlobals();
|
||||
|
||||
/**
|
||||
* Retrieves a typed ability system globals instance.
|
||||
* 获取特定类型的技能系统全局实例。
|
||||
* @param DesiredClass The desired class type. 所需的类类型。
|
||||
* @return The typed ability system globals instance. 特定类型的技能系统全局实例。
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|Globals", meta=(DynamicOutputParam=ReturnValue, DeterminesOutputType=DesiredClass))
|
||||
static const UAbilitySystemGlobals* GetTypedAbilitySystemGloabls(TSubclassOf<UAbilitySystemGlobals> DesiredClass);
|
||||
|
||||
/**
|
||||
* Registers an event receiver for global events.
|
||||
* 为全局事件注册事件接收器。
|
||||
* @param NewReceiver The event receiver to register. 要注册的事件接收器。
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "GGA|Globals", meta=(DefaultToSelf="NewReceiver"))
|
||||
static void RegisterEventReceiver(TScriptInterface<IGGA_AbilitySystemGlobalsEventReceiver> NewReceiver);
|
||||
|
||||
/**
|
||||
* Unregisters an event receiver from global events.
|
||||
* 从全局事件取消注册事件接收器。
|
||||
* @param NewReceiver The event receiver to unregister. 要取消注册的事件接收器。
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category = "GGA|Globals", meta=(DefaultToSelf="NewReceiver"))
|
||||
static void UnregisterEventReceiver(TScriptInterface<IGGA_AbilitySystemGlobalsEventReceiver> NewReceiver);
|
||||
|
||||
/**
|
||||
* Retrieves all currently loaded attribute default curve tables.
|
||||
* 获取当前加载的所有属性默认曲线表。
|
||||
* @return Array of curve tables. 曲线表数组。
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGA|Globals")
|
||||
TArray<UCurveTable*> GetAttributeDefaultsTables() const;
|
||||
|
||||
/**
|
||||
* Initializes attribute set defaults for an ability system component.
|
||||
* 为技能系统组件初始化属性集默认值。
|
||||
* @param AbilitySystem The ability system component. 技能系统组件。
|
||||
* @param GroupName The attribute group name. 属性组名称。
|
||||
* @param Level The level to initialize. 初始化等级。
|
||||
* @param bInitialInit Whether this is the initial initialization. 是否为初始初始化。
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure=false, Category = "GGA|Globals")
|
||||
void InitAttributeSetDefaults(UAbilitySystemComponent* AbilitySystem, const FGGA_AttributeGroupName& GroupName, int32 Level = 1, bool bInitialInit = false) const;
|
||||
|
||||
/**
|
||||
* Applies a single attribute default to an ability system component.
|
||||
* 为技能系统组件应用单个属性默认值。
|
||||
* @param AbilitySystem The ability system component. 技能系统组件。
|
||||
* @param InAttribute The attribute to apply. 要应用的属性。
|
||||
* @param GroupName The attribute group name. 属性组名称。
|
||||
* @param Level The level to apply. 应用等级。
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure=false, Category = "GGA|Globals")
|
||||
void ApplyAttributeDefault(UAbilitySystemComponent* AbilitySystem, FGameplayAttribute& InAttribute, const FGGA_AttributeGroupName& GroupName, int32 Level) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* List of registered event receivers.
|
||||
* 注册的事件接收器列表。
|
||||
*/
|
||||
UPROPERTY()
|
||||
TArray<TScriptInterface<IGGA_AbilitySystemGlobalsEventReceiver>> Receivers;
|
||||
};
|
||||
|
||||
/**
|
||||
* Interface for receiving global ability system events.
|
||||
* 接收全局技能系统事件的接口。
|
||||
*/
|
||||
UINTERFACE()
|
||||
class GENERICGAMEPLAYABILITIES_API UGGA_AbilitySystemGlobalsEventReceiver : public UInterface
|
||||
{
|
||||
GENERATED_BODY()
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation class for global ability system event receiver.
|
||||
* 全局技能系统事件接收器的实现类。
|
||||
*/
|
||||
class GENERICGAMEPLAYABILITIES_API IGGA_AbilitySystemGlobalsEventReceiver
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
/**
|
||||
* Handles global pre-gameplay effect spec application.
|
||||
* 处理全局游戏效果规格应用前的事件。
|
||||
* @param Spec The gameplay effect spec. 游戏效果规格。
|
||||
* @param AbilitySystemComponent The ability system component. 技能系统组件。
|
||||
*/
|
||||
virtual void ReceiveGlobalPreGameplayEffectSpecApply(FGameplayEffectSpec& Spec, UAbilitySystemComponent* AbilitySystemComponent);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Virtual function for handling pre-gameplay effect spec application.
|
||||
* 处理游戏效果规格应用前的虚函数。
|
||||
* @param Spec The gameplay effect spec. 游戏效果规格。
|
||||
* @param AbilitySystemComponent The ability system component. 技能系统组件。
|
||||
*/
|
||||
virtual void OnGlobalPreGameplayEffectSpecApply(FGameplayEffectSpec& Spec, UAbilitySystemComponent* AbilitySystemComponent) = 0;
|
||||
|
||||
/**
|
||||
* Blueprint event for handling pre-gameplay effect spec application.
|
||||
* 处理游戏效果规格应用前的蓝图事件。
|
||||
* @param Spec The gameplay effect spec. 游戏效果规格。
|
||||
* @param AbilitySystemComponent The ability system component. 技能系统组件。
|
||||
* @param OutDynamicTagsAppendToSpec Tags to append to the spec (output). 要附加到规格的标签(输出)。
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category="GGA|Global", meta=(DisplayName="On Global Pre Gameplay Effect Spec Apply"))
|
||||
void OnGlobalPreGameplayEffectSpecApply_Bp(const FGameplayEffectSpec& Spec, UAbilitySystemComponent* AbilitySystemComponent, FGameplayTagContainer& OutDynamicTagsAppendToSpec);
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "StructUtils/InstancedStruct.h"
|
||||
#include "Abilities/GameplayAbilityTargetTypes.h"
|
||||
#include "GGA_GameplayAbilityTargetData_Payload.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct GENERICGAMEPLAYABILITIES_API FGGA_GameplayAbilityTargetData_Payload : public FGameplayAbilityTargetData
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
virtual ~FGGA_GameplayAbilityTargetData_Payload() override
|
||||
{
|
||||
}
|
||||
|
||||
FGGA_GameplayAbilityTargetData_Payload()
|
||||
{
|
||||
};
|
||||
|
||||
FGGA_GameplayAbilityTargetData_Payload(const FInstancedStruct& InPayload)
|
||||
: Payload(InPayload)
|
||||
{
|
||||
}
|
||||
|
||||
virtual UScriptStruct* GetScriptStruct() const override
|
||||
{
|
||||
return FGGA_GameplayAbilityTargetData_Payload::StaticStruct();
|
||||
}
|
||||
|
||||
virtual FString ToString() const override
|
||||
{
|
||||
return TEXT("FGGA_GameplayAbilityTargetData_Payload");
|
||||
}
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Targeting)
|
||||
FInstancedStruct Payload;
|
||||
|
||||
bool NetSerialize(FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess)
|
||||
{
|
||||
return Payload.NetSerialize(Ar, Map, bOutSuccess);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct TStructOpsTypeTraits<FGGA_GameplayAbilityTargetData_Payload> : public TStructOpsTypeTraitsBase2<FGGA_GameplayAbilityTargetData_Payload>
|
||||
{
|
||||
enum
|
||||
{
|
||||
WithNetSerializer = true, // For now this is REQUIRED for FGameplayAbilityTargetDataHandle net serialization to work
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,108 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameplayEffectTypes.h"
|
||||
#include "Runtime/Launch/Resources/Version.h"
|
||||
#if ENGINE_MINOR_VERSION < 5
|
||||
#include "InstancedStruct.h"
|
||||
#else
|
||||
#include "StructUtils/InstancedStruct.h"
|
||||
#endif
|
||||
#include "GGA_GameplayEffectContext.generated.h"
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
USTRUCT()
|
||||
struct GENERICGAMEPLAYABILITIES_API FGGA_GameplayEffectContext : public FGameplayEffectContext
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
virtual FGameplayEffectContext* Duplicate() const override;
|
||||
virtual UScriptStruct* GetScriptStruct() const override;
|
||||
virtual bool NetSerialize(FArchive& Ar, UPackageMap* Map, bool& bOutSuccess) override;
|
||||
|
||||
TArray<FInstancedStruct>& GetPayloads();
|
||||
|
||||
void AddOrOverwriteData(const FInstancedStruct& DataInstance);
|
||||
const FInstancedStruct* FindPayloadByType(const UScriptStruct* PayloadType) const;
|
||||
FInstancedStruct* FindPayloadByType(const UScriptStruct* PayloadType);
|
||||
FInstancedStruct* FindOrAddPayloadByType(const UScriptStruct* PayloadType);
|
||||
FInstancedStruct* AddPayloadByType(const UScriptStruct* PayloadType);
|
||||
bool RemovePayloadByType(const UScriptStruct* PayloadType);
|
||||
|
||||
/** Find payload of a specific type in this context (mutable version). If not found, null will be returned. */
|
||||
template <typename T>
|
||||
T* FindMutablePayloadByType()
|
||||
{
|
||||
if (FInstancedStruct* FoundData = FindPayloadByType(T::StaticStruct()))
|
||||
{
|
||||
return FoundData->GetMutablePtr<T>();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/** Find payload of a specific type in this context. If not found, null will be returned. */
|
||||
template <typename T>
|
||||
const T* FindPayload() const
|
||||
{
|
||||
if (const FInstancedStruct* FoundData = FindPayloadByType(T::StaticStruct()))
|
||||
{
|
||||
return FoundData->GetPtr<T>();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/** Find payload of a specific type in this context. If not found, a new default instance will be added. */
|
||||
template <typename T>
|
||||
const T& FindOrAddPayload()
|
||||
{
|
||||
if (const T* ExistingData = FindPayload<T>())
|
||||
{
|
||||
return *ExistingData;
|
||||
}
|
||||
FInstancedStruct* NewData = AddPayloadByType(T::StaticStruct());
|
||||
return NewData->Get<T>();
|
||||
}
|
||||
|
||||
/** Find payload of a specific type in this context. (mutable version). If not found, a new default instance will be added. */
|
||||
template <typename T>
|
||||
T& FindOrAddMutablePayload()
|
||||
{
|
||||
if (T* ExistingData = FindMutablePayloadByType<T>())
|
||||
{
|
||||
return *ExistingData;
|
||||
}
|
||||
FInstancedStruct* NewData = AddPayloadByType(T::StaticStruct());
|
||||
return NewData->GetMutable<T>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* FindOrAddMutablePayloadPtr()
|
||||
{
|
||||
if (T* ExistingData = FindMutablePayloadByType<T>())
|
||||
{
|
||||
return ExistingData;
|
||||
}
|
||||
FInstancedStruct* NewData = AddPayloadByType(T::StaticStruct());
|
||||
return NewData->GetMutablePtr<T>();
|
||||
}
|
||||
|
||||
protected:
|
||||
UPROPERTY()
|
||||
TArray<FInstancedStruct> Payloads;
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct TStructOpsTypeTraits<FGGA_GameplayEffectContext> : TStructOpsTypeTraitsBase2<FGGA_GameplayEffectContext>
|
||||
{
|
||||
enum
|
||||
{
|
||||
WithNetSerializer = true,
|
||||
WithCopy = true
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user