第一次提交

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,74 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Perception/AIPerceptionTypes.h"
#include "Tasks/TargetingFilterTask_BasicFilterTemplate.h"
#include "GCS_TargetingFilterTask_Affiliation.generated.h"
/**
* Filters targets based on team affiliation.
* 根据队伍归属过滤目标。
*/
UCLASS(meta=(DisplayName="GCS:FilterTask (Affiliation)"))
class GENERICCOMBATSYSTEM_API UGCS_TargetingFilterTask_Affiliation : public UTargetingFilterTask_BasicFilterTemplate
{
GENERATED_BODY()
protected:
/**
* Affiliation filter settings.
* 归属过滤设置。
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Filter")
FAISenseAffiliationFilter DetectionByAffiliation;
/**
* Whether to check for CombatTeamAgentInterface.
* 是否检查CombatTeamAgentInterface。
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Filter")
bool bLookCombatTeamAgentInterface{true};
/**
* Whether to check for GenericTeamAgentInterface.
* 是否检查GenericTeamAgentInterface。
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Filter")
bool bLookGenericTeamAgentInterface{true};
/**
* Whether to ignore target actor who has no team assigned(teamId:255)
* 是否忽略没有队伍的目标即TeamId为255
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Filter")
bool bIgnoreTargetWithNoTeam{true};
/**
* Determines if a target should be filtered based on affiliation.
* 根据归属确定是否应过滤目标。
* @param TargetingHandle The targeting request handle. 目标请求句柄。
* @param TargetData The target data. 目标数据。
* @return True if the target should be filtered. 如果应过滤目标返回true。
*/
virtual bool ShouldFilterTarget(const FTargetingRequestHandle& TargetingHandle, const FTargetingDefaultResultData& TargetData) const override;
/**
* Gets the source team ID.
* 获取来源队伍ID。
* @param TargetingHandle The targeting request handle. 目标请求句柄。
* @param TargetData The target data. 目标数据。
* @return The source team ID. 来源队伍ID。
*/
virtual FGenericTeamId GetSourceTeamId(const FTargetingRequestHandle& TargetingHandle, const FTargetingDefaultResultData& TargetData) const;
/**
* Gets the target team ID.
* 获取目标队伍ID。
* @param TargetingHandle The targeting request handle. 目标请求句柄。
* @param TargetData The target data. 目标数据。
* @return The target team ID. 目标队伍ID。
*/
virtual FGenericTeamId GetTargetTeamId(const FTargetingRequestHandle& TargetingHandle, const FTargetingDefaultResultData& TargetData) const;
};

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 "GCS_TargetingFilterTask_IsDead.generated.h"
/**
* Filters out dead targets.
* 过滤掉已死亡的目标。
*/
UCLASS(meta=(DisplayName="GCS:FilterTask (IsDead)"))
class GENERICCOMBATSYSTEM_API UGCS_TargetingFilterTask_IsDead : public UTargetingFilterTask_BasicFilterTemplate
{
GENERATED_BODY()
protected:
/**
* Determines if a target should be filtered based on death state.
* 根据死亡状态确定是否应过滤目标。
* @param TargetingHandle The targeting request handle. 目标请求句柄。
* @param TargetData The target data. 目标数据。
* @return True if the target is dead and should be filtered. 如果目标已死亡且应过滤返回true。
*/
virtual bool ShouldFilterTarget(const FTargetingRequestHandle& TargetingHandle, const FTargetingDefaultResultData& TargetData) const override;
};

View File

@@ -0,0 +1,50 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameplayTagContainer.h"
#include "Tasks/TargetingFilterTask_BasicFilterTemplate.h"
#include "GCS_TargetingFilterTask_TagsRequirements.generated.h"
/**
* Filters targets based on a gameplay tag query.
* 根据游戏标签查询过滤目标。
*/
UCLASS(meta=(DisplayName="GCS:FilterTask (TagsRequirements)"))
class GENERICCOMBATSYSTEM_API UGCS_TargetingFilterTask_TagsRequirements : public UTargetingFilterTask_BasicFilterTemplate
{
GENERATED_BODY()
protected:
/**
* Whether to invert the filter result.
* 是否反转过滤结果。
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Filter")
bool bInvert{false};
/**
* The tag query that targets must match.
* 目标必须匹配的标签查询。
* @note If empty, no filtering is applied. 如果为空,不应用过滤。
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Filter", meta = (DisplayName = "Query Must Match"))
FGameplayTagQuery TagQuery;
/**
* Whether to fall back to GameplayTagAssetInterface if AbilitySystemComponent fails.
* 如果AbilitySystemComponent失败是否回退到GameplayTagAssetInterface。
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Filter")
bool bLookingForTagAssetInterface{false};
/**
* Determines if a target should be filtered.
* 确定是否应过滤目标。
* @param TargetingHandle The targeting request handle. 目标请求句柄。
* @param TargetData The target data. 目标数据。
* @return True if the target should be filtered. 如果应过滤目标返回true。
*/
virtual bool ShouldFilterTarget(const FTargetingRequestHandle& TargetingHandle, const FTargetingDefaultResultData& TargetData) const override;
};

View File

@@ -0,0 +1,29 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Tasks/TargetingFilterTask_BasicFilterTemplate.h"
#include "GCS_TargetingFilterTask_TraceInstance.generated.h"
/**
* Filters targets based on the CanHitActor check of a collision trace instance.
* 根据碰撞检测实例的CanHitActor检查过滤目标。
* @note Requires SourceObject to be a collision trace instance.
* @注意 需要SourceObject是碰撞检测实例。
*/
UCLASS(meta=(DisplayName="GCS:Filter Task (TraceInstance CanHitActor)"))
class GENERICCOMBATSYSTEM_API UGCS_TargetingFilterTask_TraceInstance : public UTargetingFilterTask_BasicFilterTemplate
{
GENERATED_BODY()
protected:
/**
* Determines if a target should be filtered.
* 确定是否应过滤目标。
* @param TargetingHandle The targeting request handle. 目标请求句柄。
* @param TargetData The target data. 目标数据。
* @return True if the target should be filtered. 如果应过滤目标返回true。
*/
virtual bool ShouldFilterTarget(const FTargetingRequestHandle& TargetingHandle, const FTargetingDefaultResultData& TargetData) const override;
};

View File

@@ -0,0 +1,59 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Abilities/GameplayAbilityTargetTypes.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Types/TargetingSystemTypes.h"
#include "GCS_TargetingFunctionLibrary.generated.h"
/**
* Extended library for targeting system utilities.
* 目标系统实用程序的扩展库。
*/
UCLASS()
class GENERICCOMBATSYSTEM_API UGCS_TargetingFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
/**
* Gets the targeting source context for a targeting request handle.
* 获取目标请求句柄的目标源上下文。
* @param TargetingHandle The targeting request handle. 目标请求句柄。
* @return The targeting source context. 目标源上下文。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GCS|Targeting System | Targeting Types")
static FTargetingSourceContext GetTargetingSourceContext(FTargetingRequestHandle TargetingHandle);
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GCS|Targeting System | Targeting Types")
static FString GetTargetingSourceContextDebugString(FTargetingRequestHandle TargetingHandle);
/**
* Gets the actor targets from a targeting request handle.
* 从目标请求句柄获取Actor目标。
* @param TargetingHandle The targeting request handle. 目标请求句柄。
* @param Targets The actor targets (output). Actor目标输出
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GCS|Targeting System | Targeting Results")
static void GetTargetingResultsActors(FTargetingRequestHandle TargetingHandle, TArray<AActor*>& Targets);
/**
* Gets the hit results for a targeting handle.
* 获取目标句柄的命中结果。
* @param TargetingHandle The targeting request handle. 目标请求句柄。
* @param OutTargets The hit results (output). 命中结果(输出)。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GCS|Targeting System | Targeting Results")
static void GetTargetingResults(FTargetingRequestHandle TargetingHandle, TArray<FHitResult>& OutTargets);
/**
* Converts targeting location info to a source context.
* 将目标位置信息转换为源上下文。
* @param LocationInfo The targeting location info. 目标位置信息。
* @return The targeting source context. 目标源上下文。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GCS|Targeting System")
static FTargetingSourceContext ConvertTargetingLocationInfoToSourceContext(FGameplayAbilityTargetingLocationInfo LocationInfo);
};

View File

@@ -0,0 +1,77 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "GCS_TargetingSourceInterface.generated.h"
/**
* Interface for objects providing targeting system information.
* 为目标系统提供信息的对象的接口。
* @note Used to provide additional targeting data.
* @注意 用于提供额外的目标数据。
*/
UINTERFACE(MinimalAPI, BlueprintType, Blueprintable)
class UGCS_TargetingSourceInterface : public UInterface
{
GENERATED_BODY()
};
/**
* Interface for targeting source objects.
* 目标源对象的接口。
*/
class GENERICCOMBATSYSTEM_API IGCS_TargetingSourceInterface
{
GENERATED_BODY()
public:
/**
* Gets the trace level for dynamic tracing.
* 获取动态追踪的追踪级别。
* @return The trace level. 追踪级别。
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category="GCS|Trace")
float GetTraceLevel() const;
virtual float GetTraceLevel_Implementation() const = 0;
/**
* Gets the trace direction for targeting.
* 获取目标的追踪方向。
* @param OutDirection The trace direction (output). 追踪方向(输出)。
* @return True if a direction is provided. 如果提供方向返回true。
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category="GCS|Trace")
bool GetTraceDirection(FVector& OutDirection) const;
virtual bool GetTraceDirection_Implementation(FVector& OutDirection) const = 0;
/**
* Gets the swept trace rotation for capsule or box traces.
* 获取胶囊或盒体追踪的旋转。
* @param OutRotation The rotation (output). 旋转(输出)。
* @return True if a rotation is provided. 如果提供旋转返回true。
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "GCS|Trace")
bool GetSweptTraceRotation(FRotator& OutRotation) const;
virtual bool GetSweptTraceRotation_Implementation(FRotator& OutRotation) const = 0;
/**
* Gets the shape component for trace properties.
* 获取追踪属性的形状组件。
* @param OutShape The shape component (output). 形状组件(输出)。
* @return True if a shape component is provided. 如果提供形状组件返回true。
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category="GCS|Trace")
bool GetTraceShape(UShapeComponent*& OutShape) const;
virtual bool GetTraceShape_Implementation(UShapeComponent*& OutShape) const = 0;
/**
* Gets additional actors to ignore during tracing.
* 获取追踪期间忽略的额外Actor。
* @return Array of actors to ignore. 忽略的Actor数组。
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category="GCS|Trace")
TArray<AActor*> GetAdditionalActorsToIgnore() const;
virtual TArray<AActor*> GetAdditionalActorsToIgnore_Implementation() const = 0;
};

View File

@@ -0,0 +1,248 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Components/PawnComponent.h"
#include "GCS_TargetingSystemComponent.generated.h"
class UTargetingPreset;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FGCS_OnTargetLockOnSignature, AActor*, NewTargetActor);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FGCS_OnTargetLockOffSignature, AActor*, PrevTargetActor);
/**
* Component for managing combat targeting.
* 管理战斗目标的组件。
*/
UCLASS(ClassGroup=(GCS), AutoExpandCategories=("GCS"), meta=(BlueprintSpawnableComponent), Blueprintable)
class GENERICCOMBATSYSTEM_API UGCS_TargetingSystemComponent : public UPawnComponent
{
GENERATED_BODY()
public:
/**
* Default constructor.
* 默认构造函数。
*/
UGCS_TargetingSystemComponent(const FObjectInitializer& ObjectInitializer);
/**
* Gets the targeting system component from an actor.
* 从Actor获取目标系统组件。
* @param Actor The actor to query. 要查询的Actor。
* @return The targeting system component. 目标系统组件。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GCS|Targeting", Meta = (DefaultToSelf="Actor"))
static UGCS_TargetingSystemComponent* GetTargetingSystemComponent(const AActor* Actor);
/**
* Retrieves lifetime replicated properties.
* 获取生命周期复制属性。
* @param OutLifetimeProps The lifetime properties. 生命周期属性。
*/
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
protected:
/**
* Called when the game starts.
* 游戏开始时调用。
*/
virtual void BeginPlay() override;
/**
* The currently targeted actor.
* 当前目标Actor。
*/
UPROPERTY(VisibleInstanceOnly, BlueprintReadWrite, Replicated, Category = "GCS|Targeting")
TObjectPtr<AActor> TargetedActor = nullptr;
/**
* List of potential target actors (server-side only).
* 潜在目标Actor列表仅限服务器
*/
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "GCS|Targeting", meta=(AllowPrivateAccess=true))
TArray<TObjectPtr<AActor>> PotentialTargets;
/**
* Whether to automatically update potential targets based on tick rate.
* 是否根据tick频率自动更新潜在目标。
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GCS|Targeting", meta=(AllowPrivateAccess=true))
bool bAutoUpdatePotentialTargets{true};
/**
* Targeting preset for searching and filtering targets.
* 用于搜索和过滤目标的目标预设。
* @note The component's owner is the SourceActor, and the component is the SourceObject.
* @注意 组件的Owner作为SourceActor组件本身作为SourceObject。
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "GCS|Targeting", meta=(AllowPrivateAccess=true))
TObjectPtr<UTargetingPreset> TargetingPreset;
/**
* Flag to indicate we should be using async targeting
* 是否使用异步定位?
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GCS|Targeting", meta=(AllowPrivateAccess=true))
bool bUseAsyncTargeting{true};
public:
/**
* Called every frame.
* 每帧调用。
* @param DeltaTime Time since last frame. 上一帧以来的时间。
* @param TickType The type of tick. tick类型。
* @param ThisTickFunction The tick function. tick函数。
*/
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
/**
* Refreshes targeting based on the delta time.
* 根据时间增量刷新目标。
* @param DeltaTime Time since last frame. 上一帧以来的时间。
*/
virtual void RefreshTargeting(float DeltaTime);
/**
* Forces collection of potential targets and selects the best one.
* 强制收集潜在目标并选择最佳目标。
*/
UFUNCTION(BlueprintCallable, Category = "GCS|Targeting")
void SearchForActorToTarget();
/**
* Selects the closest actor from potential targets within a radius.
* 从潜在目标中选择指定范围内最近的Actor。
* @param Radius The search radius. 搜索半径。
* @return The closest actor. 最近的Actor。
*/
UFUNCTION(BlueprintCallable, Category = "GCS|Targeting")
AActor* SelectClosestActorFromPotentialTargets(float Radius = 100) const;
/**
* Filters actors using a targeting preset.
* 使用目标预设过滤Actor。
* @param InTargetingPreset The targeting preset. 目标预设。
* @param InTargets The input targets. 输入目标。
* @param OutActors The filtered actors (output). 过滤后的Actor输出
* @return True if filtering succeeded. 如果过滤成功返回true。
*/
UFUNCTION(BlueprintCallable, Category = "GCS|Targeting", meta=(ExpandBoolAsExecs="ReturnValue"))
bool FilterActorsWithPreset(UTargetingPreset* InTargetingPreset, const TArray<AActor*> InTargets, TArray<AActor*>& OutActors);
/**
* Selects a target from potential targets.
* 从潜在目标中选择一个目标。
*/
virtual void SelectFromPotentialTargets();
/**
* Switches to a new target based on direction.
* 根据方向切换到新目标。
* @param RightDirection Whether to switch to the right. 是否向右切换。
*/
UFUNCTION(BlueprintCallable, Category = "GCS|Targeting")
void StaticSwitchToNewTarget(bool RightDirection);
/**
* Refreshes the list of potential targets using the targeting preset.
* 使用目标预设刷新潜在目标列表。
*/
virtual void RefreshPotentialTargets();
/**
* Checks if an actor can be targeted.
* 检查Actor是否可以被目标。
* @param ActorToTarget The actor to check. 要检查的Actor。
* @return True if the actor can be targeted. 如果Actor可被目标返回true。
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "GCS|Targeting")
bool CanBeTargeted(AActor* ActorToTarget);
virtual bool CanBeTargeted_Implementation(AActor* ActorToTarget);
/**
* Gets the currently targeted actor.
* 获取当前目标Actor。
* @return The targeted actor. 目标Actor。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GCS|Targeting")
FORCEINLINE AActor* GetTargetedActor() { return TargetedActor; }
/**
* Sets the targeted actor.
* 设置目标Actor。
* @param NewActor The new target actor. 新目标Actor。
*/
UFUNCTION(BlueprintCallable, Category = "GCS|Targeting")
void SetTargetedActor(AActor* NewActor);
private:
/**
* Sets the targeted actor with optional RPC.
* 设置目标Actor可选择是否发送RPC。
* @param NewActor The new target actor. 新目标Actor。
* @param bSendRpc Whether to send RPC. 是否发送RPC。
*/
void SetTargetedActor(AActor* NewActor, bool bSendRpc);
/**
* Client RPC to set the targeted actor.
* 设置目标Actor的客户端RPC。
* @param NewActor The new target actor. 新目标Actor。
*/
UFUNCTION(Client, Reliable)
void ClientSetTargetedActor(AActor* NewActor);
virtual void ClientSetTargetedActor_Implementation(AActor* NewActor);
/**
* Server RPC to set the targeted actor.
* 设置目标Actor的服务器RPC。
* @param NewActor The new target actor. 新目标Actor。
*/
UFUNCTION(Server, Reliable)
void ServerSetTargetedActor(AActor* NewActor);
virtual void ServerSetTargetedActor_Implementation(AActor* NewActor);
protected:
/**
* Handles target lock-off events.
* 处理目标解锁事件。
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "GCS|Targeting")
void OnLockOff();
virtual void OnLockOff_Implementation();
/**
* Handles target lock-on events.
* 处理目标锁定事件。
*/
UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "GCS|Targeting")
void OnLockOn();
virtual void OnLockOn_Implementation();
/**
* Delegate for target lock-on events.
* 目标锁定事件的委托。
*/
UPROPERTY(BlueprintAssignable, Category="GCS|Targeting")
FGCS_OnTargetLockOnSignature OnTargetLockOnEvent;
/**
* Delegate for target lock-off events.
* 目标解锁事件的委托。
*/
UPROPERTY(BlueprintAssignable, Category="GCS|Targeting")
FGCS_OnTargetLockOffSignature OnTargetLockOffEvent;
/**
* Calculates the view angle to a target actor.
* 计算到目标Actor的视角角度。
* @param TargetActor The target actor. 目标Actor。
* @return The view angle. 视角角度。
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GCS|Targeting")
virtual float CalculateViewAngle(const AActor* TargetActor);
};

View File

@@ -0,0 +1,132 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CollisionShape.h"
#include "Engine/CollisionProfile.h"
#include "Types/TargetingSystemTypes.h"
#include "ScalableFloat.h"
#include "Tasks/TargetingTask.h"
#include "UObject/Object.h"
#include "GCS_TargetingSelectionTask_LineTrace.generated.h"
class UTargetingSubsystem;
struct FCollisionQueryParams;
struct FTargetingDebugInfo;
struct FTargetingDefaultResultData;
struct FTargetingRequestHandle;
struct FTraceDatum;
struct FTraceHandle;
/**
* @class UGCS_TargetingSelectionTask_LineTrace
* Selection task that can perform a synchronous or asynchronous line trace, always generate hit results.
* to find all targets up to the first blocking hit (or its end point).
*/
UCLASS(Blueprintable, meta=(DisplayName="GCS:SelectionTask (Line Trace)"))
class GENERICCOMBATSYSTEM_API UGCS_TargetingSelectionTask_LineTrace : public UTargetingTask
{
GENERATED_BODY()
public:
UGCS_TargetingSelectionTask_LineTrace(const FObjectInitializer& ObjectInitializer);
/** Evaluation function called by derived classes to process the targeting request */
virtual void Execute(const FTargetingRequestHandle& TargetingHandle) const override;
protected:
/** Native Event to get the source location for the Trace */
UFUNCTION(BlueprintCallable, BlueprintPure, BlueprintCallable, BlueprintPure, BlueprintNativeEvent, Category = "Target Trace Selection")
FVector GetSourceLocation(const FTargetingRequestHandle& TargetingHandle) const;
/** Native Event to get a source location offset for the Trace */
UFUNCTION(BlueprintCallable, BlueprintPure, BlueprintNativeEvent, Category = "Target Trace Selection")
FVector GetSourceOffset(const FTargetingRequestHandle& TargetingHandle) const;
/**
* Native Event to get the direction for the Trace
* Default will use pawn's control rotation or fallback to actor forward direction.
*/
UFUNCTION(BlueprintCallable, BlueprintPure, BlueprintNativeEvent, Category = "Target Trace Selection")
FVector GetTraceDirection(const FTargetingRequestHandle& TargetingHandle) const;
/** Native Event to get the length for the Trace */
UFUNCTION(BlueprintCallable, BlueprintPure, BlueprintNativeEvent, Category = "Target Trace Selection")
float GetTraceLength(const FTargetingRequestHandle& TargetingHandle) const;
UFUNCTION(BlueprintCallable, BlueprintPure, BlueprintNativeEvent, Category = "Target Trace Selection")
float GetTraceLevel(const FTargetingRequestHandle& TargetingHandle) const;
/** Native Event to get additional actors the Trace should ignore */
UFUNCTION(BlueprintCallable, BlueprintPure, BlueprintNativeEvent, Category = "Target Trace Selection")
void GetAdditionalActorsToIgnore(const FTargetingRequestHandle& TargetingHandle, TArray<AActor*>& OutAdditionalActorsToIgnore) const;
protected:
/** Method to process the trace task immediately */
void ExecuteImmediateTrace(const FTargetingRequestHandle& TargetingHandle) const;
/** Method to process the trace task asynchronously */
void ExecuteAsyncTrace(const FTargetingRequestHandle& TargetingHandle) const;
/** Callback for an async trace */
void HandleAsyncTraceComplete(const FTraceHandle& InTraceHandle, FTraceDatum& InTraceDatum, FTargetingRequestHandle TargetingHandle) const;
/** Method to take the hit results and store them in the targeting result data */
void ProcessHitResults(const FTargetingRequestHandle& TargetingHandle, const TArray<FHitResult>& Hits) const;
/** Setup CollisionQueryParams for the trace */
void InitCollisionParams(const FTargetingRequestHandle& TargetingHandle, FCollisionQueryParams& OutParams) const;
protected:
/** The trace channel to use */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Target Trace Selection | Collision Data")
TEnumAsByte<ETraceTypeQuery> TraceChannel;
/** The collision profile name to use instead of trace channel (does not work for async traces) */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Target Trace Selection | Collision Data")
FCollisionProfileName CollisionProfileName;
/** The default trace length to use if GetTraceLength is not overridden by a child */
UPROPERTY(EditAnywhere, BlueprintReadOnly, BlueprintReadOnly, Category = "Target Trace Selection | Trace Data")
FScalableFloat DefaultTraceLength = 10.0f;
/** The default source location offset used by GetSourceOffset */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Target Trace Selection | Trace Data")
FVector DefaultSourceOffset = FVector::ZeroVector;
/** Indicates the trace should perform a complex trace */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Target Trace Selection | Trace Data")
uint8 bComplexTrace : 1;
/** Indicates the trace should ignore the source actor */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Target Trace Selection | Trace Data")
uint8 bIgnoreSourceActor : 1;
/** Indicates the trace should ignore the source actor */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Target Trace Selection | Trace Data")
uint8 bIgnoreInstigatorActor : 1;
// If there were no hits, add a default HitResult at the end of the trace
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Target Trace Selection | Trace Data")
uint8 bGenerateDefaultHitResult : 1;
protected:
#if WITH_EDITOR
virtual bool CanEditChange(const FProperty* InProperty) const override;
#endif
/** Debug Helper Methods */
#if ENABLE_DRAW_DEBUG
private:
virtual void DrawDebug(UTargetingSubsystem* TargetingSubsystem, FTargetingDebugInfo& Info, const FTargetingRequestHandle& TargetingHandle, float XOffset, float YOffset,
int32 MinTextRowsToAdvance) const override;
/** Draw debug info showing the results of the shape trace used for targeting. */
virtual void DrawDebugTrace(const FTargetingRequestHandle TargetingHandle, const FVector& StartLocation, const FVector& EndLocation, const bool bHit, const TArray<FHitResult>& Hits) const;
void BuildTraceResultsDebugString(const FTargetingRequestHandle& TargetingHandle, const TArray<FTargetingDefaultResultData>& TargetResults) const;
void ResetTraceResultsDebugString(const FTargetingRequestHandle& TargetingHandle) const;
#endif // ENABLE_DRAW_DEBUG
/** ~Debug Helper Methods */
};

View File

@@ -0,0 +1,67 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Tasks/TargetingSelectionTask_Trace.h"
#include "GCS_TargetingSelectionTask_TraceExt.generated.h"
class UDEPRECATED_GCS_CollisionTraceInstance;
/**
* @class UGCS_TargetingSelectionTask_TraceExt
* Specialized version of SelectionTask_Trace,Allow passing data via source object to Trace execution.
* @attention SourceObject should be provided and implement GCS_TargetingSourceInterface.
*/
UCLASS(meta=(DisplayName="GCS:SelectionTask (Trace)"))
class GENERICCOMBATSYSTEM_API UGCS_TargetingSelectionTask_TraceExt : public UTargetingSelectionTask_Trace
{
GENERATED_BODY()
public:
virtual void Execute(const FTargetingRequestHandle& TargetingHandle) const override;
protected:
/**
* If ticked, user context's source location as trace source location.
* Or it will try to get context's source actor location first,then fall back to context's source location.
* 如果勾选会使用上下文的源位置作为Trace的源位置。
* 否则它会先从上下文的源Actor上获取位置如果没有Actor则回退到上下文的源位置。
*/
UPROPERTY(EditAnywhere, Category = "Target Trace Selection | Trace Data")
bool bUseContextLocationAsSourceLocation{false};
virtual FVector GetSourceLocation_Implementation(const FTargetingRequestHandle& TargetingHandle) const override;
virtual FVector GetTraceDirection_Implementation(const FTargetingRequestHandle& TargetingHandle) const override;
virtual void GetAdditionalActorsToIgnore_Implementation(const FTargetingRequestHandle& TargetingHandle, TArray<AActor*>& OutAdditionalActorsToIgnore) const override;
/** Native Event to get the source location for the Trace */
UE_DEPRECATED(1.5, "CollisionTraceInstance no longer required!")
UFUNCTION(BlueprintNativeEvent, Category = "Target Trace Selection", meta=(DeprecatedFunction))
UDEPRECATED_GCS_CollisionTraceInstance* GetSourceTraceInstance(const FTargetingRequestHandle& TargetingHandle) const;
UFUNCTION(BlueprintNativeEvent, Category = "Target Trace Selection")
float GetTraceLevel(const FTargetingRequestHandle& TargetingHandle) const;
UPROPERTY(EditAnywhere, Category = "Target Trace Selection | Trace Data")
bool bTraceLengthLevel{true};
virtual float GetTraceLength_Implementation(const FTargetingRequestHandle& TargetingHandle) const override;
UPROPERTY(EditAnywhere, Category = "Target Trace Selection | Swept Data")
bool bSweptTraceRadiusLevel{true};
virtual float GetSweptTraceRadius_Implementation(const FTargetingRequestHandle& TargetingHandle) const override;
UPROPERTY(EditAnywhere, Category = "Target Trace Selection | Swept Data")
bool bSweptTraceCapsuleHalfHeightLevel{true};
virtual float GetSweptTraceCapsuleHalfHeight_Implementation(const FTargetingRequestHandle& TargetingHandle) const override;
UPROPERTY(EditAnywhere, Category = "Target Trace Selection | Swept Data")
bool bSweptTraceBoxHalfExtentLevel{true};
virtual FVector GetSweptTraceBoxHalfExtents_Implementation(const FTargetingRequestHandle& TargetingHandle) const override;
};

View File

@@ -0,0 +1,55 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GCS_TargetingSelectionTask_TraceExt.h"
#include "GCS_TargetingSelectionTask_TraceExt_BindShape.generated.h"
class UShapeComponent;
UENUM(BlueprintType)
enum class EGCS_TraceDataModifyType :uint8
{
None UMETA(DisplayName="None"),
Add UMETA(DisplayName="Add"),
Multiply UMETA(DisplayName = "Multiply"),
};
/**
*
*/
UCLASS(meta=(DisplayName="GCS:SelectionTask (Trace Bind Shape)"))
class GENERICCOMBATSYSTEM_API UGCS_TargetingSelectionTask_TraceExt_BindShape : public UGCS_TargetingSelectionTask_TraceExt
{
GENERATED_BODY()
public:
virtual void Execute(const FTargetingRequestHandle& TargetingHandle) const override;
protected:
UPROPERTY(EditAnywhere, Category = "Target Trace Selection | Trace Data")
EGCS_TraceDataModifyType SweptTraceRadiusModType{EGCS_TraceDataModifyType::None};
virtual float GetSweptTraceRadius_Implementation(const FTargetingRequestHandle& TargetingHandle) const override;
UPROPERTY(EditAnywhere, Category = "Target Trace Selection | Swept Data")
EGCS_TraceDataModifyType SweptTraceCapsuleHalfHeightModType{EGCS_TraceDataModifyType::None};
virtual float GetSweptTraceCapsuleHalfHeight_Implementation(const FTargetingRequestHandle& TargetingHandle) const override;
UPROPERTY(EditAnywhere, Category = "Target Trace Selection | Swept Data")
EGCS_TraceDataModifyType SweptTraceBoxHalfExtentModType{EGCS_TraceDataModifyType::None};
virtual FVector GetSweptTraceBoxHalfExtents_Implementation(const FTargetingRequestHandle& TargetingHandle) const override;
virtual UShapeComponent* GetTraceShape(const FTargetingRequestHandle& TargetingHandle) const;
virtual FRotator GetSweptTraceRotation_Implementation(const FTargetingRequestHandle& TargetingHandle) const override;
public:
#if WITH_EDITORONLY_DATA
virtual EDataValidationResult IsDataValid(class FDataValidationContext& Context) const override;
#endif
};