第一次提交

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,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
};