第一次提交

This commit is contained in:
不明不惑
2026-03-03 01:23:02 +08:00
commit 3e434877e8
1053 changed files with 102411 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "SmartObjectRuntime.h"
#include "Abilities/GameplayAbility.h"
#include "GGS_GameplayAbility_Interaction.generated.h"
class UGGS_InteractionSystemComponent;
class USmartObjectComponent;
/**
* Core gameplay ability for handling interactions.
* 处理交互的核心游戏技能。
*/
UCLASS(BlueprintType, Blueprintable)
class GENERICGAMESYSTEM_API UGGS_GameplayAbility_Interaction : public UGameplayAbility
{
GENERATED_BODY()
public:
/**
* Constructor for the interaction gameplay ability.
* 交互游戏技能构造函数。
*/
UGGS_GameplayAbility_Interaction();
/**
* Activates the interaction ability.
* 激活交互技能。
* @param Handle The ability specification handle. 技能规格句柄。
* @param ActorInfo Information about the actor using the ability. 使用技能的Actor信息。
* @param ActivationInfo Information about the ability activation. 技能激活信息。
* @param TriggerEventData Optional event data triggering the ability. 触发技能的可选事件数据。
*/
virtual void ActivateAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo,
const FGameplayEventData* TriggerEventData) override;
/**
* Ends the interaction ability.
* 结束交互技能。
* @param Handle The ability specification handle. 技能规格句柄。
* @param ActorInfo Information about the actor using the ability. 使用技能的Actor信息。
* @param ActivationInfo Information about the ability activation. 技能激活信息。
* @param bReplicateEndAbility Whether to replicate the end ability call. 是否同步结束技能调用。
* @param bWasCancelled Whether the ability was cancelled. 技能是否被取消。
*/
virtual void EndAbility(const FGameplayAbilitySpecHandle Handle, const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo, bool bReplicateEndAbility,
bool bWasCancelled) override;
protected:
/**
* Attempts to claim an interaction with a smart object.
* 尝试认领与智能对象的交互。
* @param Index The interaction option index. 交互选项索引。
* @param ClaimedHandle The claimed smart object handle (output). 认领的智能对象句柄(输出)。
* @return True if the interaction was claimed successfully, false otherwise. 如果交互成功认领返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, Category="GCS|Interaction", meta=(ExpandBoolAsExecs=ReturnValue))
bool TryClaimInteraction(int32 Index, FSmartObjectClaimHandle& ClaimedHandle);
/**
* Called when the interactable actor changes.
* 可交互演员变更时调用。
* @param OldActor The previous interactable actor. 之前的可交互演员。
* @param NewActor The new interactable actor. 新的可交互演员。
*/
UFUNCTION(BlueprintNativeEvent, Category="GCS|Interaction")
void OnInteractActorChanged(AActor* OldActor, AActor* NewActor);
/**
* Reference to the interaction system component.
* 交互系统组件的引用。
*/
UPROPERTY(BlueprintReadOnly, Category="GCS|Interaction")
TObjectPtr<UGGS_InteractionSystemComponent> InteractionSystem{nullptr};
#if WITH_EDITORONLY_DATA
/**
* Validates data in the editor.
* 在编辑器中验证数据。
* @param Context The data validation context. 数据验证上下文。
* @return The validation result. 验证结果。
*/
virtual EDataValidationResult IsDataValid(class FDataValidationContext& Context) const override;
#endif
};

View File

@@ -0,0 +1,55 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameplayBehaviorConfig.h"
#include "GameplayTagContainer.h"
#include "UObject/Object.h"
#include "GGS_GameplayBehaviorConfig_InteractionWithAbility.generated.h"
class UGameplayAbility;
class UUserWidget;
/**
* Configuration for ability-based interaction behavior.
* 基于技能的交互行为配置。
*/
UCLASS(DisplayName="Gameplay Behavior Config Interaction (GGS)")
class GENERICGAMESYSTEM_API UGGS_GameplayBehaviorConfig_InteractionWithAbility : public UGameplayBehaviorConfig
{
GENERATED_BODY()
public:
/**
* Constructor for the interaction behavior config.
* 交互行为配置构造函数。
*/
UGGS_GameplayBehaviorConfig_InteractionWithAbility();
/**
* The ability to grant and activate when interaction begins.
* 交互开始时赋予并激活的技能。
* @note Must be instanced and not LocalOnly. Does not support event-triggered abilities.
* @注意 必须是实例化的技能不能是LocalOnly。不支持事件触发的技能。
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Interaction")
TSoftClassPtr<UGameplayAbility> AbilityToGrant;
/**
* The level of the ability, used for visual distinctions.
* 技能等级,用于视觉区分。
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Interaction")
int32 AbilityLevel{0};
#if WITH_EDITORONLY_DATA
/**
* Validates data in the editor.
* 在编辑器中验证数据。
* @param Context The data validation context. 数据验证上下文。
* @return The validation result. 验证结果。
*/
virtual EDataValidationResult IsDataValid(class FDataValidationContext& Context) const override;
#endif
};

View File

@@ -0,0 +1,92 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameplayAbilitySpecHandle.h"
#include "GameplayBehavior.h"
#include "Abilities/GameplayAbilityTypes.h"
#include "GGS_GameplayBehavior_InteractionWithAbility.generated.h"
/**
* Gameplay behavior for ability-based interactions.
* 基于技能的交互游戏行为。
*/
UCLASS(DisplayName="GameplayBehavior_Interaction (GGS)", NotBlueprintable)
class GENERICGAMESYSTEM_API UGGS_GameplayBehavior_InteractionWithAbility : public UGameplayBehavior
{
GENERATED_BODY()
public:
/**
* Triggers the interaction behavior.
* 触发交互行为。
* @param InAvatar The avatar actor. 化身演员。
* @param Config The behavior config. 行为配置。
* @param SmartObjectOwner The smart object owner. 智能对象拥有者。
* @return True if the behavior was triggered successfully, false otherwise. 如果行为成功触发返回true否则返回false。
*/
virtual bool Trigger(AActor& InAvatar, const UGameplayBehaviorConfig* Config, AActor* SmartObjectOwner) override;
/**
* Ends the behavior.
* 结束行为。
* @param Avatar The avatar actor. 化身演员。
* @param bInterrupted Whether the behavior was interrupted. 行为是否被中断。
*/
virtual void EndBehavior(AActor& Avatar, const bool bInterrupted) override;
/**
* Checks the validity of the ability settings.
* 检查技能设置的有效性。
* @param Config The behavior config. 行为配置。
* @param OutAbilityClass The ability class (output). 技能类(输出)。
* @param OutAbilityLevel The ability level (output). 技能等级(输出)。
* @return True if the settings are valid, false otherwise. 如果设置有效返回true否则返回false。
*/
bool CheckValidAbilitySetting(const UGameplayBehaviorConfig* Config, TSubclassOf<UGameplayAbility>& OutAbilityClass, int32& OutAbilityLevel);
/**
* The ability class granted for the interaction.
* 为交互授予的技能类。
*/
UPROPERTY()
TSubclassOf<UGameplayAbility> GrantedAbilityClass{nullptr};
/**
* Handle for the granted ability spec.
* 授予技能规格的句柄。
*/
FGameplayAbilitySpecHandle AbilitySpecHandle;
/**
* Indicates if the behavior was interrupted.
* 表示行为是否被中断。
*/
bool bBehaviorWasInterrupted = false;
/**
* Indicates if the ability has ended.
* 表示技能是否已结束。
*/
bool bAbilityEnded = false;
/**
* Indicates if the ability was cancelled.
* 表示技能是否被取消。
*/
bool bAbilityWasCancelled = false;
/**
* Delegate handle for ability end notification.
* 技能结束通知的委托句柄。
*/
FDelegateHandle AbilityEndedDelegateHandle;
/**
* Called when the ability ends.
* 技能结束时调用。
* @param EndedData The ability end data. 技能结束数据。
*/
virtual void OnAbilityEndedCallback(const FAbilityEndedData& EndedData);
};

View File

@@ -0,0 +1,79 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "GGS_InteractableInterface.generated.h"
/**
* Interface for actors to handle interaction events.
* 处理交互事件的演员接口。
*/
UINTERFACE()
class GENERICGAMESYSTEM_API UGGS_InteractableInterface : public UInterface
{
GENERATED_BODY()
};
/**
* Implementation class for interactable actors.
* 可交互演员的实现类。
*/
class GENERICGAMESYSTEM_API IGGS_InteractableInterface
{
GENERATED_BODY()
public:
/**
* Retrieves the display name for the interactable actor.
* 获取可交互演员的显示名称。
* @return The display name. 显示名称。
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category="GGS|Interaction")
FText GetInteractionDisplayName() const;
virtual FText GetInteractionDisplayNameText_Implementation() const;
/**
* Called when the actor is selected by the interaction system.
* 演员被交互系统选中时调用。
* @param Instigator The instigating actor, usually the player. 发起者,通常是玩家。
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category="GGS|Interaction")
void OnInteractionSelected(AActor* Instigator);
/**
* Called when the actor is deselected by the interaction system.
* 演员被交互系统取消选中时调用。
* @param Instigator The instigating actor. 发起者。
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category="GGS|Interaction")
void OnInteractionDeselected(AActor* Instigator);
/**
* Called when interaction with the actor starts.
* 与演员交互开始时调用。
* @param Instigator The instigating actor. 发起者。
* @param Index The interaction option index. 交互选项索引。
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category="GGS|Interaction")
void OnInteractionStarted(AActor* Instigator, int32 Index);
/**
* Called when interaction with the actor ends.
* 与演员交互结束时调用。
* @param Instigator The instigating actor. 发起者。
* @param Index The interaction option index. 交互选项索引。
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category="GGS|Interaction")
void OnInteractionEnded(AActor* Instigator, int32 Index);
/**
* Called when an interaction option is selected.
* 交互选项被选中时调用。
* @param Instigator The instigating actor. 发起者。
* @param OptionIndex The selected option index. 选中的选项索引。
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category="GGS|Interaction")
void OnInteractionOptionSelected(AActor* Instigator, int32 OptionIndex);
};

View File

@@ -0,0 +1,40 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Engine/DataTable.h"
#include "Engine/DataAsset.h"
#include "GGS_InteractionDefinition.generated.h"
/**
* Base class for interaction settings, used in smart object interaction entrances.
* 交互设置基类,用于智能对象交互入口。
*/
UCLASS(BlueprintType, Blueprintable)
class GENERICGAMESYSTEM_API UGGS_InteractionDefinition : public UDataAsset
{
GENERATED_BODY()
public:
/**
* Display text for the interaction.
* 交互的显示文本。
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Interaction")
FText Text;
/**
* Sub-text for the interaction.
* 交互的子文本。
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Interaction")
FText SubText;
/**
* Input action that triggers the interaction.
* 触发交互的输入动作。
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Interaction", meta = (RowType = "/Script/CommonUI.CommonInputActionDataBase"))
FDataTableRowHandle TriggeringInputAction;
};

View File

@@ -0,0 +1,108 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Runtime/Launch/Resources/Version.h"
#include "SmartObjectRuntime.h"
#include "SmartObjectSubsystem.h"
#include "SmartObjectTypes.h"
#if ENGINE_MINOR_VERSION >= 6
#include "SmartObjectRequestTypes.h"
#endif
#include "Engine/DataTable.h"
#include "UObject/Object.h"
#include "GGS_InteractionStructLibrary.generated.h"
class UGGS_InteractionSystemComponent;
class UAbilitySystemComponent;
class UGGS_InteractionDefinition;
/**
* Structure wrapping an interaction definition for smart object interaction.
* 封装智能对象交互的交互定义结构。
*/
USTRUCT(DisplayName="Interaction Entrance")
struct GENERICGAMESYSTEM_API FGGS_SmartObjectInteractionEntranceData : public FSmartObjectDefinitionData
{
GENERATED_BODY()
/**
* Interaction definition containing static data for player interaction.
* 包含玩家交互静态数据的交互定义。
* @note Replicated across the network.
* @注意 通过网络同步。
*/
UPROPERTY(EditAnywhere, Category="Interaction", meta=(DisplayName="Definition"))
TSoftObjectPtr<UGGS_InteractionDefinition> DefinitionDA{nullptr};
};
/**
* Structure representing an interaction option.
* 表示交互选项的结构。
*/
USTRUCT(BlueprintType)
struct GENERICGAMESYSTEM_API FGGS_InteractionOption
{
GENERATED_BODY()
/**
* Interaction definition associated with this option.
* 与此选项关联的交互定义。
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Interaction")
TObjectPtr<UGGS_InteractionDefinition> Definition{nullptr};
/**
* Smart object request result for this option. Not replicated.
* 此选项的智能对象请求结果。未网络同步。
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, NotReplicated, Category="Interaction")
FSmartObjectRequestResult RequestResult;
/**
* Smart object behavior definition for this option.
* 此选项的智能对象行为定义。
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, NotReplicated, Category="Interaction")
TObjectPtr<const USmartObjectBehaviorDefinition> BehaviorDefinition;
/**
* Index of the associated smart object slot, used for UI sorting.
* 关联智能对象槽的索引用于UI排序。
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Interaction")
int32 SlotIndex{-1};
/**
* State of the associated smart object slot, used for UI input rules.
* 关联智能对象槽的状态用于UI输入规则。
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Interaction")
ESmartObjectSlotState SlotState{ESmartObjectSlotState::Free};
/**
* Equality operator for comparing interaction options.
* 交互选项的相等比较运算符。
*/
friend bool operator==(const FGGS_InteractionOption& Lhs, const FGGS_InteractionOption& RHS);
/**
* Inequality operator for comparing interaction options.
* 交互选项的不等比较运算符。
*/
friend bool operator!=(const FGGS_InteractionOption& Lhs, const FGGS_InteractionOption& RHS);
/**
* Less-than operator for sorting interaction options by slot index.
* 按槽索引排序交互选项的比较运算符。
*/
friend bool operator<(const FGGS_InteractionOption& Lhs, const FGGS_InteractionOption& RHS);
/**
* Converts the interaction option to a string representation.
* 将交互选项转换为字符串表示。
* @return String representation of the option. 选项的字符串表示。
*/
FString ToString() const;
};

View File

@@ -0,0 +1,332 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GGS_InteractionStructLibrary.h"
#include "SmartObjectSubsystem.h"
#include "Components/ActorComponent.h"
#include "GGS_InteractionSystemComponent.generated.h"
class UCommonUserWidget;
class UGameplayBehavior;
/**
* Delegate for interaction events.
* 交互事件的委托。
*/
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FInteractionEventSignature);
/**
* Delegate for changes in the interactable actor.
* 可交互演员变更的委托。
*/
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FInteractableActorChangedSignature, AActor*, OldActor, AActor*, NewActor);
/**
* Delegate for changes in the interacting state.
* 交互状态变更的委托。
*/
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FInteractingStateChangedSignature, bool, bInteracting);
/**
* Delegate for changes in the number of interactable actors.
* 可交互演员数量变更的委托。
*/
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FInteractableActorNumChangedSignature, int32, ActorsNum);
/**
* Component for managing interactions with smart objects.
* 管理与智能对象交互的组件。
*/
UCLASS(Blueprintable, BlueprintType, ClassGroup=(GGS), meta=(BlueprintSpawnableComponent))
class GENERICGAMESYSTEM_API UGGS_InteractionSystemComponent : public UActorComponent
{
GENERATED_BODY()
public:
/**
* Constructor for the interaction system component.
* 交互系统组件构造函数。
*/
UGGS_InteractionSystemComponent();
/**
* Retrieves lifetime replicated properties.
* 获取生命周期内同步的属性。
* @param OutLifetimeProps The replicated properties. 同步的属性。
*/
virtual void GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const override;
/**
* Retrieves the interaction system component from an actor.
* 从演员获取交互系统组件。
* @param Actor The actor to query. 要查询的演员。
* @return The interaction system component. 交互系统组件。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGS|InteractionSystem", meta=(DefaultToSelf="Actor"))
static UGGS_InteractionSystemComponent* GetInteractionSystemComponent(const AActor* Actor);
/**
* Cycles through interactable actors.
* 循环切换可交互演员。
* @param bNext Whether to cycle to the next actor. 是否切换到下一个演员。
*/
UFUNCTION(Server, Reliable, BlueprintCallable, Category="GGS|InteractionSystem")
void CycleInteractableActors(bool bNext);
/**
* Triggers a search for potential interactable actors.
* 触发潜在可交互演员的搜索。
*/
UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category="GGS|InteractionSystem")
void SearchInteractableActors();
/**
* Sets a new array of interactable actors.
* 设置新的可交互演员数组。
* @param NewActors The new interactable actors. 新的可交互演员。
*/
UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category="GGS|InteractionSystem")
void SetInteractableActors(TArray<AActor*> NewActors);
/**
* Sets the number of interactable actors.
* 设置可交互演员的数量。
* @param NewNum The new number of interactable actors. 可交互演员的新数量。
*/
void SetInteractableActorsNum(int32 NewNum);
/**
* Retrieves the array of interactable actors.
* 获取可交互演员数组。
* @return The interactable actors. 可交互演员。
*/
TArray<AActor*> GetInteractableActors() const { return InteractableActors; }
/**
* Retrieves the number of interactable actors.
* 获取可交互演员的数量。
* @return The number of interactable actors. 可交互演员数量。
*/
int32 GetNumOfInteractableActors() const { return NumsOfInteractableActors; }
/**
* Sets the current interactable actor.
* 设置当前可交互演员。
* @param InActor The actor to set. 要设置的演员。
*/
UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category="GGS|InteractionSystem")
void SetInteractableActor(AActor* InActor);
/**
* Retrieves the current interactable actor.
* 获取当前可交互演员。
* @return The interactable actor. 可交互演员。
*/
AActor* GetInteractableActor() const { return InteractableActor; }
/**
* Delegate for when the interactable actor changes.
* 可交互演员变更时的委托。
*/
UPROPERTY(BlueprintAssignable)
FInteractableActorChangedSignature OnInteractableActorChangedEvent;
/**
* Delegate for when the number of interactable actors changes.
* 可交互演员数量变更时的委托。
*/
UPROPERTY(BlueprintAssignable)
FInteractableActorNumChangedSignature OnInteractableActorNumChangedEvent;
/**
* Delegate for when the interacting state changes.
* 交互状态变更时的委托。
*/
UPROPERTY(BlueprintAssignable)
FInteractingStateChangedSignature OnInteractingStateChangedEvent;
/**
* Delegate for when the interaction options change.
* 交互选项变更时的委托。
*/
UPROPERTY(BlueprintAssignable)
FInteractionEventSignature OnInteractionOptionsChangedEvent;
/**
* Delegate for when a search for interactable actors is triggered.
* 触发可交互演员搜索时的委托。
*/
UPROPERTY(BlueprintAssignable)
FInteractionEventSignature OnSearchInteractableActorsEvent;
/**
* Retrieves the smart object request filter.
* 获取智能对象请求过滤器。
* @return The smart object request filter. 智能对象请求过滤器。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, BlueprintNativeEvent, Category="GGS|InteractionSystem")
FSmartObjectRequestFilter GetSmartObjectRequestFilter();
virtual FSmartObjectRequestFilter GetSmartObjectRequestFilter_Implementation();
/**
* Starts an interaction with the specified option index.
* 开始与指定选项索引的交互。
* @param NewIndex The interaction option index. 交互选项索引。
*/
UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category="GGS|InteractionSystem")
virtual void StartInteraction(int32 NewIndex = 0);
/**
* Ends the current interaction.
* 结束当前交互。
*/
UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category="GGS|InteractionSystem")
virtual void EndInteraction();
/**
* Performs an instant interaction with the specified option index.
* 执行与指定选项索引的即时交互。
*/
UFUNCTION(BlueprintCallable, BlueprintAuthorityOnly, Category="GGS|InteractionSystem")
void InstantInteraction(int32 NewIndex = 0);
/**
* Checks if an interaction is in progress.
* 检查是否正在进行交互。
* @return True if interacting, false otherwise. 如果正在交互返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGS|InteractionSystem")
bool IsInteracting() const;
/**
* Retrieves the current interacting option index.
* 获取当前交互选项索引。
* @return The interacting option index. 交互选项索引。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGS|InteractionSystem")
int32 GetInteractingOption() const;
/**
* Retrieves the current interaction options.
* 获取当前交互选项。
* @return The interaction options. 交互选项。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GGS|InteractionSystem")
const TArray<FGGS_InteractionOption>& GetInteractionOptions() const { return InteractionOptions; }
protected:
/**
* Called when the interactable actor changes.
* 可交互演员变更时调用。
* @param OldActor The previous interactable actor. 之前的可交互演员。
*/
UFUNCTION()
virtual void OnInteractableActorChanged(AActor* OldActor);
/**
* Called when the number of interactable actors changes.
* 可交互演员数量变更时调用。
*/
UFUNCTION()
virtual void OnInteractableActorsNumChanged();
/**
* Called when the potential interactable actors changes.
* 可交互演员变更时调用。
*/
UFUNCTION(BlueprintNativeEvent, Category="GGS|InteractionSystem")
void OnInteractableActorsChanged();
/**
* Called when a smart object event occurs.
* 智能对象事件发生时调用。
* @param EventData The smart object event data. 智能对象事件数据。
*/
UFUNCTION()
virtual void OnSmartObjectEventCallback(const FSmartObjectEventData& EventData);
/**
* Called when interaction options change.
* 交互选项变更时调用。
*/
UFUNCTION()
virtual void OnInteractionOptionsChanged();
/**
* Called when the interacting option index changes.
* 交互选项索引变更时调用。
* @param PrevOptionIndex The previous option index. 之前的选项索引。
*/
UFUNCTION(BlueprintNativeEvent, Category="GGS|InteractionSystem")
void OnInteractingOptionChanged(int32 PrevOptionIndex);
/**
* Refreshes interaction options based on smart object request results.
* 根据智能对象请求结果刷新交互选项。
*/
virtual void RefreshOptionsForActor();
/**
* Array of potential interactable actors. Not replicated.
* 潜在可交互演员数组。未网络同步。
*/
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="GGS|InteractionSystem")
TArray<TObjectPtr<AActor>> InteractableActors;
/**
* Number of potential interactable actors, replicated to owning client.
* 潜在可交互演员数量,同步到拥有客户端。
*/
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, ReplicatedUsing=OnInteractableActorsNumChanged, Category="GGS|InteractionSystem")
int32 NumsOfInteractableActors{0};
/**
* Current selected interactable actor, replicated for owner only.
* 当前选中的可交互演员,仅针对拥有者同步。
*/
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "GGS|InteractionSystem", ReplicatedUsing=OnInteractableActorChanged)
TObjectPtr<AActor> InteractableActor;
/**
* Default filter for searching interactable smart objects.
* 搜索可交互智能对象的默认过滤器。
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="GGS|InteractionSystem")
FSmartObjectRequestFilter DefaultRequestFilter;
/**
* If checked, whenever potential interactable actors changes, the first actor in the list will be selected as currency interactable actor.
* 如果勾选,始终使用潜在交互演员中的第一个作为当前选择。
*/
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, ReplicatedUsing=OnInteractableActorsNumChanged, Category="GGS|InteractionSystem")
bool bNewActorHasPriority{false};
/**
* Current available interaction options, replicated for owner only.
* 当前可用的交互选项,仅针对拥有者同步。
*/
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="GGS|InteractionSystem", ReplicatedUsing=OnInteractionOptionsChanged)
TArray<FGGS_InteractionOption> InteractionOptions;
/**
* Indicates if an interaction is in progress.
* 表示是否正在进行交互。
*/
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="GGS|InteractionSystem")
bool bInteracting{false};
/**
* Current interacting option index (-1 if no interaction).
* 当前交互选项索引(无交互时为-1
*/
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="GGS|InteractionSystem", ReplicatedUsing=OnInteractingOptionChanged)
int32 InteractingOption{INDEX_NONE};
/**
* Map of smart object slot handles to delegate handles.
* 智能对象槽句柄到委托句柄的映射。
*/
TMap<FSmartObjectSlotHandle, FDelegateHandle> SlotCallbacks;
};

View File

@@ -0,0 +1,70 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GGS_InteractionStructLibrary.h"
#include "SmartObjectSubsystem.h"
#include "SmartObjectTypes.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "GGS_SmartObjectFunctionLibrary.generated.h"
class UGameplayInteractionSmartObjectBehaviorDefinition;
class UGameplayBehaviorSmartObjectBehaviorDefinition;
class UGameplayBehaviorConfig;
class USmartObjectBehaviorDefinition;
/**
* Blueprint function library for smart object interactions.
* 智能对象交互的蓝图函数库。
*/
UCLASS()
class GENERICGAMESYSTEM_API UGGS_SmartObjectFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
/**
* Retrieves the gameplay behavior config from a smart object behavior definition.
* 从智能对象行为定义获取游戏行为配置。
* @param BehaviorDefinition The smart object behavior definition. 智能对象行为定义。
* @return The gameplay behavior config. 游戏行为配置。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GGS|SmartObject")
static UGameplayBehaviorConfig* GetGameplayBehaviorConfig(const USmartObjectBehaviorDefinition* BehaviorDefinition);
/**
* Finds a specific gameplay behavior config by class.
* 按类查找特定游戏行为配置。
* @param BehaviorDefinition The smart object behavior definition. 智能对象行为定义。
* @param DesiredClass The desired config class. 期望的配置类。
* @param OutConfig The found config (output). 找到的配置(输出)。
* @return True if the config was found, false otherwise. 如果找到配置返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, Category = "GGS|SmartObject", meta=(DeterminesOutputType="DesiredClass", DynamicOutputParam="OutConfig", ExpandBoolAsExecs="ReturnValue"))
static bool FindGameplayBehaviorConfig(const USmartObjectBehaviorDefinition* BehaviorDefinition, TSubclassOf<UGameplayBehaviorConfig> DesiredClass, UGameplayBehaviorConfig*& OutConfig);
/**
* Searches for smart object slots with interaction entrances on an actor.
* 在演员上搜索带有交互入口的智能对象槽。
* @param Filter The search filter. 搜索过滤器。
* @param SearchActor The actor to search. 要搜索的演员。
* @param OutResults The found smart object slot candidates (output). 找到的智能对象槽候选(输出)。
* @param UserActor Optional actor for additional data in condition evaluation. 用于条件评估的可选演员。
* @return True if at least one candidate was found, false otherwise. 如果找到至少一个候选返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, BlueprintPure = False, Category = "GGS|SmartObject", Meta = (ReturnDisplayName = "bSuccess"))
static bool FindSmartObjectsWithInteractionEntranceInActor(const FSmartObjectRequestFilter& Filter, AActor* SearchActor, TArray<FSmartObjectRequestResult>& OutResults,
const AActor* UserActor = nullptr);
/**
* Finds the interaction definition for a smart object slot.
* 查找智能对象槽的交互定义。
* @param WorldContext The world context object. 世界上下文对象。
* @param SmartObjectSlotHandle The smart object slot handle. 智能对象槽句柄。
* @param OutDefinition The interaction definition (output). 交互定义(输出)。
* @return True if the definition was found, false otherwise. 如果找到定义返回true否则返回false。
*/
UFUNCTION(BlueprintCallable, Category="GGS|SmartObject", meta=(WorldContext="WorldContext", ExpandBoolAsExecs="ReturnValue"))
static bool FindInteractionDefinitionFromSmartObjectSlot(UObject* WorldContext, FSmartObjectSlotHandle SmartObjectSlotHandle, UGGS_InteractionDefinition*& OutDefinition);
};

View File

@@ -0,0 +1,27 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Tasks/TargetingFilterTask_BasicFilterTemplate.h"
#include "GGS_TargetingFilterTask_InteractionSmartObjects.generated.h"
/**
* Filter task for selecting interactable smart objects.
* 选择可交互智能对象的过滤任务。
*/
UCLASS(meta=(DisplayName="(GGS)FilterTask:InteractionSmartObject"))
class GENERICGAMESYSTEM_API UGGS_TargetingFilterTask_InteractionSmartObjects : public UTargetingFilterTask_BasicFilterTemplate
{
GENERATED_BODY()
protected:
/**
* Determines if a target should be filtered based on interaction criteria.
* 根据交互标准确定是否过滤目标。
* @param TargetingHandle The targeting request handle. 目标请求句柄。
* @param TargetData The target data. 目标数据。
* @return True if the target should be filtered, false otherwise. 如果目标应被过滤返回true否则返回false。
*/
virtual bool ShouldFilterTarget(const FTargetingRequestHandle& TargetingHandle, const FTargetingDefaultResultData& TargetData) const override;
};

View File

@@ -0,0 +1,124 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Abilities/Tasks/AbilityTask.h"
#include "SmartObjectRuntime.h"
#include "SmartObjectTypes.h"
#include "GGS_AbilityTask_UseSmartObjectWithGameplayBehavior.generated.h"
class UGameplayBehavior;
/**
* Ability task for using a smart object with gameplay behavior.
* 使用智能对象和游戏行为的技能任务。
*/
UCLASS()
class GENERICGAMESYSTEM_API UGGS_AbilityTask_UseSmartObjectWithGameplayBehavior : public UAbilityTask
{
GENERATED_BODY()
public:
/**
* Constructor for the ability task.
* 技能任务构造函数。
*/
UGGS_AbilityTask_UseSmartObjectWithGameplayBehavior(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
/**
* Creates an ability task to use a smart object with gameplay behavior.
* 创建使用智能对象和游戏行为的技能任务。
* @param OwningAbility The owning gameplay ability. 拥有的游戏技能。
* @param ClaimHandle The smart object claim handle. 智能对象认领句柄。
* @param ClaimPriority The claim priority. 认领优先级。
* @return The created ability task. 创建的技能任务。
*/
UFUNCTION(BlueprintCallable, Category = "GGS|Interaction", meta = (HidePin = "OwningAbility", DefaultToSelf = "OwningAbility", BlueprintInternalUseOnly = "TRUE"))
static UGGS_AbilityTask_UseSmartObjectWithGameplayBehavior* UseSmartObjectWithGameplayBehavior(UGameplayAbility* OwningAbility, FSmartObjectClaimHandle ClaimHandle,
ESmartObjectClaimPriority ClaimPriority = ESmartObjectClaimPriority::Normal);
/**
* Sets the smart object claim handle.
* 设置智能对象认领句柄。
* @param Handle The claim handle. 认领句柄。
*/
void SetClaimHandle(const FSmartObjectClaimHandle& Handle) { ClaimedHandle = Handle; }
protected:
/**
* Activates the ability task.
* 激活技能任务。
*/
virtual void Activate() override;
/**
* Called when the task is destroyed.
* 任务销毁时调用。
* @param bInOwnerFinished Whether the owner finished the task. 拥有者是否完成任务。
*/
virtual void OnDestroy(bool bInOwnerFinished) override;
/**
* Starts the interaction with the smart object.
* 开始与智能对象的交互。
* @return True if the interaction started successfully, false otherwise. 如果交互成功开始返回true否则返回false。
*/
bool StartInteraction();
/**
* Called when the smart object behavior finishes.
* 智能对象行为完成时调用。
* @param Behavior The gameplay behavior. 游戏行为。
* @param Avatar The avatar actor. 化身演员。
* @param bInterrupted Whether the behavior was interrupted. 行为是否被中断。
*/
void OnSmartObjectBehaviorFinished(UGameplayBehavior& Behavior, AActor& Avatar, const bool bInterrupted);
/**
* Called when the smart object slot is invalidated.
* 智能对象槽失效时调用。
* @param ClaimHandle The claim handle. 认领句柄。
* @param State The slot state. 槽状态。
*/
void OnSlotInvalidated(const FSmartObjectClaimHandle& ClaimHandle, const ESmartObjectSlotState State);
/**
* Delegate for when the interaction succeeds.
* 交互成功时的委托。
*/
UPROPERTY(BlueprintAssignable)
FGenericGameplayTaskDelegate OnSucceeded;
/**
* Delegate for when the interaction fails.
* 交互失败时的委托。
*/
UPROPERTY(BlueprintAssignable)
FGenericGameplayTaskDelegate OnFailed;
/**
* The gameplay behavior for the interaction.
* 交互的游戏行为。
*/
UPROPERTY()
TObjectPtr<UGameplayBehavior> GameplayBehavior;
/**
* The claimed smart object handle.
* 认领的智能对象句柄。
*/
FSmartObjectClaimHandle ClaimedHandle;
/**
* Delegate handle for behavior finished notification.
* 行为完成通知的委托句柄。
*/
FDelegateHandle OnBehaviorFinishedNotifyHandle;
/**
* Indicates if the behavior has finished.
* 表示行为是否已完成。
*/
bool bBehaviorFinished;
};