第一次提交

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,95 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GGA_AbilityTargetActor_Trace.h"
#include "DrawDebugHelpers.h"
#include "Engine/CollisionProfile.h"
#include "GGA_AbilityTargetActor_LineTrace.generated.h"
/**
* 可重用、配置的线形检测目标捕获Actor。
* 与UGAT_WaitTargetDataUsingActor配合使用。
*/
UCLASS()
class GENERICGAMEPLAYABILITIES_API AGGA_AbilityTargetActor_LineTrace : public AGGA_AbilityTargetActor_Trace
{
GENERATED_BODY()
public:
AGGA_AbilityTargetActor_LineTrace();
/**
* Configure the TargetActor for use. This TargetActor could be used in multiple abilities and there's no guarantee
* what state it will be in. You will need to make sure that only one ability is using this TargetActor at a time.
*
* @param InStartLocation Location to trace from.
* @param InAimingTag Optional. Predicted GameplayTag for aiming. Only used if we mofify spread while aiming. If used,
* must set InAimingRemovalTag also.
* @param InAimingRemovalTag Optional. Predicted GameplayTag for aiming removal. Only used if we mofify spread while
* aiming. If used, must set InAimingTag also.
* @param InTraceProfile Collision profile to use for tracing.
* @param InFilter Hit Actors must pass this filter to be returned in the TargetData.
* @param InReticleClass Reticle that will appear on top of acquired targets. Reticles will be spawned/despawned as targets are acquired/lost.
* @param InReticleParams Parameters for world reticle. Usage of these parameters is dependent on the reticle.
* @param bInIgnoreBlockingHits Ignore blocking collision hits in the trace. Useful if you want to target through walls.
* @param bInShouldProduceTargetDataOnServer If set, this TargetActor will produce TargetData on the Server in addition
* to the client and the client will just send a generic "Confirm" event to the server. If false, the client will send
* the TargetData to the Server. This is handled by the WaitTargetDataUsingActor AbilityTask.
* @param bInUsePersistentHitResults Should HitResults persist while targeting? HitResults are cleared on Confirm/Cancel or
* when new HitResults take their place.
* @param bInDebug When true, this TargetActor will show debug lines of the trace and hit results.
* @param bInTraceAffectsAimPitch Does the trace affect the aiming pitch?
* @param bInTraceFromPlayerViewPoint Should we trace from the player ViewPoint instead of the StartLocation? The
* TargetData HitResults will still have the StartLocation for the TraceStart. This is useful for FPS where we want
* to trace from the player ViewPoint but draw the bullet tracer from the weapon muzzle.
* TODO: AI Controllers should fall back to muzzle location. Not implemented yet.
* @param bInUseAImingSpreadMod Should we modify spread based on if we're aiming? If true, must set InAimingTag and
* InAimingRemovalTag.
* @param InMaxRange Max range for this trace.
* @param InBaseSpread Base targeting spread in degrees.
* @param InAimingSpreadMod Optional. Multiplicative modifier to spread if aiming.
* @param InTargetingSpreadIncrement Amount spread increments from continuous targeting in degrees.
* @param InTargetingSpreadMax Maximum amount of spread for continuous targeting in degrees.
* @param InMaxHitResultsPerTrace Max hit results that a trace can return. < 1 just returns the trace end point.
* @param InNumberOfTraces Number of traces to perform. Intended to be used with BaseSpread for multi-shot weapons
* like shotguns. Not intended to be used with PersistentHitsResults. If using PersistentHitResults, NumberOfTraces is
* hardcoded to 1. You will need to add support for this in your project if you need it.
*/
UFUNCTION(BlueprintCallable, Category = "GGA|TargetActor")
void Configure(
UPARAM(DisplayName = "Start Location") const FGameplayAbilityTargetingLocationInfo& InStartLocation,
UPARAM(DisplayName = "Aiming Tag") FGameplayTag InAimingTag,
UPARAM(DisplayName = "Aiming Removal Tag") FGameplayTag InAimingRemovalTag,
UPARAM(DisplayName = "Trace Profile") FCollisionProfileName InTraceProfile,
UPARAM(DisplayName = "Filter") FGameplayTargetDataFilterHandle InFilter,
UPARAM(DisplayName = "Reticle Class") TSubclassOf<AGameplayAbilityWorldReticle> InReticleClass,
UPARAM(DisplayName = "Reticle Params") FWorldReticleParameters InReticleParams,
UPARAM(DisplayName = "Ignore Blocking Hits") bool bInIgnoreBlockingHits = false,
UPARAM(DisplayName = "Should Produce Target Data on Server") bool bInShouldProduceTargetDataOnServer = false,
UPARAM(DisplayName = "Use Persistent Hit Results") bool bInUsePersistentHitResults = false,
UPARAM(DisplayName = "Debug") bool bInDebug = false,
UPARAM(DisplayName = "Trace Affects Aim Pitch") bool bInTraceAffectsAimPitch = true,
UPARAM(DisplayName = "Trace From Player ViewPoint") bool bInTraceFromPlayerViewPoint = false,
UPARAM(DisplayName = "Use Aiming Spread Mod") bool bInUseAimingSpreadMod = false,
UPARAM(DisplayName = "Max Range") float InMaxRange = 999999.0f,
UPARAM(DisplayName = "Base Targeting Spread") float InBaseSpread = 0.0f,
UPARAM(DisplayName = "Aiming Spread Mod") float InAimingSpreadMod = 0.0f,
UPARAM(DisplayName = "Targeting Spread Increment") float InTargetingSpreadIncrement = 0.0f,
UPARAM(DisplayName = "Targeting Spread Max") float InTargetingSpreadMax = 0.0f,
UPARAM(DisplayName = "Max Hit Results Per Trace") int32 InMaxHitResultsPerTrace = 1,
UPARAM(DisplayName = "Number of Traces") int32 InNumberOfTraces = 1
);
protected:
virtual void DoTrace(TArray<FHitResult>& HitResults, const UWorld* World, const FGameplayTargetDataFilterHandle FilterHandle, const FVector& Start, const FVector& End, FName ProfileName,
const FCollisionQueryParams Params) override;
virtual void ShowDebugTrace(TArray<FHitResult>& HitResults, EDrawDebugTrace::Type DrawDebugType, float Duration = 2.0f) override;
#if ENABLE_DRAW_DEBUG
// Util for drawing result of multi line trace from KismetTraceUtils.h
void DrawDebugLineTraceMulti(const UWorld* World, const FVector& Start, const FVector& End, EDrawDebugTrace::Type DrawDebugType, bool bHit, const TArray<FHitResult>& OutHits,
FLinearColor TraceColor, FLinearColor TraceHitColor, float DrawTime);
#endif // ENABLE_DRAW_DEBUG
};

View File

@@ -0,0 +1,105 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GGA_AbilityTargetActor_Trace.h"
#include "DrawDebugHelpers.h"
#include "GGA_AbilityTargetActor_SphereTrace.generated.h"
/**
* 可重用、配置的球形检测目标捕获Actor。
* 与UETA_WaitTargetDataUsingActor配合使用。
*/
UCLASS()
class GENERICGAMEPLAYABILITIES_API AGGA_AbilityTargetActor_SphereTrace : public AGGA_AbilityTargetActor_Trace
{
GENERATED_BODY()
public:
AGGA_AbilityTargetActor_SphereTrace();
/**球形检测半径*/
UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (ExposeOnSpawn = true), Category = "GGA|TargetActor")
float TraceSphereRadius;
/**
* Configure the TargetActor for use. This TargetActor could be used in multiple abilities and there's no guarantee
* what state it will be in. You will need to make sure that only one ability is using this TargetActor at a time.
*
* @param InStartLocation Location to trace from.
* @param InAimingTag Optional. Predicted GameplayTag for aiming. Only used if we mofify spread while aiming. If used,
* must set InAimingRemovalTag also.
* @param InAimingRemovalTag Optional. Predicted GameplayTag for aiming removal. Only used if we mofify spread while
* aiming. If used, must set InAimingTag also.
* @param InTraceProfile Collision profile to use for tracing.
* @param InFilter Hit Actors must pass this filter to be returned in the TargetData.
* @param InReticleClass Reticle that will appear on top of acquired targets. Reticles will be spawned/despawned as targets are acquired/lost.
* @param InReticleParams Parameters for world reticle. Usage of these parameters is dependent on the reticle.
* @param bInIgnoreBlockingHits Ignore blocking collision hits in the trace. Useful if you want to target through walls.
* @param bInShouldProduceTargetDataOnServer If set, this TargetActor will produce TargetData on the Server in addition
* to the client and the client will just send a generic "Confirm" event to the server. If false, the client will send
* the TargetData to the Server. This is handled by the WaitTargetDataUsingActor AbilityTask.
* @param bInUsePersistentHitResults Should HitResults persist while targeting? HitResults are cleared on Confirm/Cancel or
* when new HitResults take their place.
* @param bInDebug When true, this TargetActor will show debug lines of the trace and hit results.
* @param bInTraceAffectsAimPitch Does the trace affect the aiming pitch?
* @param bInTraceFromPlayerViewPoint Should we trace from the player ViewPoint instead of the StartLocation? The
* TargetData HitResults will still have the StartLocation for the TraceStart. This is useful for FPS where we want
* to trace from the player ViewPoint but draw the bullet tracer from the weapon muzzle.
* TODO: AI Controllers should fall back to muzzle location. Not implemented yet.
* @param bInUseAImingSpreadMod Should we modify spread based on if we're aiming? If true, must set InAimingTag and
* InAimingRemovalTag.
* @param InMaxRange Max range for this trace.
* @param InTraceSphereRadius Radius for the sphere trace.
* @param InBaseSpread Base targeting spread in degrees.
* @param InAimingSpreadMod Optional. Multiplicative modifier to spread if aiming.
* @param InTargetingSpreadIncrement Amount spread increments from continuous targeting in degrees.
* @param InTargetingSpreadMax Maximum amount of spread for continuous targeting in degrees.
* @param InMaxHitResultsPerTrace Max hit results that a trace can return. < 1 just returns the trace end point.
* @param InNumberOfTraces Number of traces to perform. Intended to be used with BaseSpread for multi-shot weapons
* like shotguns. Not intended to be used with PersistentHitsResults. If using PersistentHitResults, NumberOfTraces is
* hardcoded to 1. You will need to add support for this in your project if you need it.
*/
UFUNCTION(BlueprintCallable, Category = "GGA|TargetActor")
void Configure(
UPARAM(DisplayName = "Start Location") const FGameplayAbilityTargetingLocationInfo& InStartLocation,
UPARAM(DisplayName = "Aiming Tag") FGameplayTag InAimingTag,
UPARAM(DisplayName = "Aiming Removal Tag") FGameplayTag InAimingRemovalTag,
UPARAM(DisplayName = "Trace Profile") FCollisionProfileName InTraceProfile,
UPARAM(DisplayName = "Filter") FGameplayTargetDataFilterHandle InFilter,
UPARAM(DisplayName = "Reticle Class") TSubclassOf<AGameplayAbilityWorldReticle> InReticleClass,
UPARAM(DisplayName = "Reticle Params") FWorldReticleParameters InReticleParams,
UPARAM(DisplayName = "Ignore Blocking Hits") bool bInIgnoreBlockingHits = false,
UPARAM(DisplayName = "Should Produce Target Data on Server") bool bInShouldProduceTargetDataOnServer = false,
UPARAM(DisplayName = "Use Persistent Hit Results") bool bInUsePersistentHitResults = false,
UPARAM(DisplayName = "Debug") bool bInDebug = false,
UPARAM(DisplayName = "Trace Affects Aim Pitch") bool bInTraceAffectsAimPitch = true,
UPARAM(DisplayName = "Trace From Player ViewPoint") bool bInTraceFromPlayerViewPoint = false,
UPARAM(DisplayName = "Use Aiming Spread Mod") bool bInUseAimingSpreadMod = false,
UPARAM(DisplayName = "Max Range") float InMaxRange = 999999.0f,
UPARAM(DisplayName = "Trace Sphere Radius") float InTraceSphereRadius = 100.0f,
UPARAM(DisplayName = "Base Targeting Spread") float InBaseSpread = 0.0f,
UPARAM(DisplayName = "Aiming Spread Mod") float InAimingSpreadMod = 0.0f,
UPARAM(DisplayName = "Targeting Spread Increment") float InTargetingSpreadIncrement = 0.0f,
UPARAM(DisplayName = "Targeting Spread Max") float InTargetingSpreadMax = 0.0f,
UPARAM(DisplayName = "Max Hit Results Per Trace") int32 InMaxHitResultsPerTrace = 1,
UPARAM(DisplayName = "Number of Traces") int32 InNumberOfTraces = 1
);
virtual void SphereTraceWithFilter(TArray<FHitResult>& OutHitResults, const UWorld* World, const FGameplayTargetDataFilterHandle FilterHandle, const FVector& Start, const FVector& End,
float Radius, FName ProfileName, const FCollisionQueryParams Params);
protected:
virtual void DoTrace(TArray<FHitResult>& HitResults, const UWorld* World, const FGameplayTargetDataFilterHandle FilterHandle, const FVector& Start, const FVector& End, FName ProfileName,
const FCollisionQueryParams Params) override;
virtual void ShowDebugTrace(TArray<FHitResult>& HitResults, EDrawDebugTrace::Type DrawDebugType, float Duration = 2.0f) override;
#if ENABLE_DRAW_DEBUG
// Utils for drawing result of multi line trace from KismetTraceUtils.h
void DrawDebugSweptSphere(const UWorld* InWorld, FVector const& Start, FVector const& End, float Radius, FColor const& Color, bool bPersistentLines = false, float LifeTime = -1.f,
uint8 DepthPriority = 0);
void DrawDebugSphereTraceMulti(const UWorld* World, const FVector& Start, const FVector& End, float Radius, EDrawDebugTrace::Type DrawDebugType, bool bHit, const TArray<FHitResult>& OutHits,
FLinearColor TraceColor, FLinearColor TraceHitColor, float DrawTime);
#endif // ENABLE_DRAW_DEBUG
};

View File

@@ -0,0 +1,163 @@
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Abilities/GameplayAbilityTargetActor.h"
#include "CollisionQueryParams.h"
#include "Engine/CollisionProfile.h"
#include "Kismet/KismetSystemLibrary.h"
#include "GGA_AbilityTargetActor_Trace.generated.h"
/**
* 可重用、配置的目标捕获Actor。子类继承实现新的检测形状。
* 与WaitTargetDataWithResuableActor配合使用。
*/
UCLASS()
class GENERICGAMEPLAYABILITIES_API AGGA_AbilityTargetActor_Trace : public AGameplayAbilityTargetActor
{
GENERATED_BODY()
public:
AGGA_AbilityTargetActor_Trace();
// 基本瞄准扩散(角度)
UPROPERTY(BlueprintReadWrite, Category = "GGA|TargetActor")
float BaseSpread;
// 瞄准扩散修改器
UPROPERTY(BlueprintReadWrite, Category = "GGA|TargetActor")
float AimingSpreadMod;
// 连续瞄准: 扩散增量
UPROPERTY(BlueprintReadWrite, Category = "GGA|TargetActor")
float TargetingSpreadIncrement;
// 连续瞄准: 最大增量
UPROPERTY(BlueprintReadWrite, Category = "GGA|TargetActor")
float TargetingSpreadMax;
// 连续瞄准的当前扩散
float CurrentTargetingSpread;
/** 是否使用瞄准扩散,开启后,检测方向会产生随机扩散(轻微改变检测方向) */
UPROPERTY(BlueprintReadWrite, Category = "GGA|TargetActor")
bool bUseAimingSpreadMod;
UPROPERTY(BlueprintReadWrite, Category = "GGA|TargetActor")
FGameplayTag AimingTag;
UPROPERTY(BlueprintReadWrite, Category = "GGA|TargetActor")
FGameplayTag AimingRemovalTag;
/** 最大范围 */
UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (ExposeOnSpawn = true), Category = "GGA|TargetActor")
float MaxRange;
/** 检测预设 */
UPROPERTY(BlueprintReadWrite, EditAnywhere, config, meta = (ExposeOnSpawn = true), Category = "GGA|TargetActor")
FCollisionProfileName TraceProfile;
/** 检测是否影响瞄准偏移(沿Y轴的旋转) */
UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (ExposeOnSpawn = true), Category = "GGA|TargetActor")
bool bTraceAffectsAimPitch;
/** 每次检测所返回的最大碰撞结果数量。0表示只返回检测终点。 */
UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (ExposeOnSpawn = true), Category = "GGA|TargetActor")
int32 MaxHitResultsPerTrace;
/** 一次性检测的次数,单发射击武器(如来福枪)只会进行一次检测,而多发射击武器(如散弹枪)可以进行多次检测。
* 不可与PersistentHits配合使用。
* 会影响十字线Actor的数量
*/
UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (ExposeOnSpawn = true), Category = "GGA|TargetActor")
int32 NumberOfTraces;
/**是否忽略阻挡Hits*/
UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (ExposeOnSpawn = true), Category = "GGA|TargetActor")
bool bIgnoreBlockingHits;
/**是否从玩家控制器的视角开始检测,否则从StartLocation开始检测*/
UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (ExposeOnSpawn = true), Category = "GGA|TargetActor")
bool bTraceFromPlayerViewPoint;
// HitResults will persist until Confirmation/Cancellation or until a new HitResult takes its place
UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (ExposeOnSpawn = true), Category = "GGA|TargetActor")
bool bUsePersistentHitResults;
/**重置扩散 */
UFUNCTION(BlueprintCallable, Category = "GGA|TargetActor")
virtual void ResetSpread();
virtual float GetCurrentSpread() const;
// 设置开始位置信息
UFUNCTION(BlueprintCallable, Category = "GGA|TargetActor")
void SetStartLocation(const FGameplayAbilityTargetingLocationInfo& InStartLocation);
// 是否在服务端产生目标数据
UFUNCTION(BlueprintCallable, Category = "GGA|TargetActor")
virtual void SetShouldProduceTargetDataOnServer(bool bInShouldProduceTargetDataOnServer);
// 设置当玩家确认目标后是否销毁此TargetingActor。
UFUNCTION(BlueprintCallable, Category = "GGA|TargetActor")
void SetDestroyOnConfirmation(bool bInDestroyOnConfirmation = false);
virtual void StartTargeting(UGameplayAbility* Ability) override;
virtual void ConfirmTargetingAndContinue() override;
virtual void CancelTargeting() override;
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
virtual void Tick(float DeltaSeconds) override;
// Traces as normal, but will manually filter all hit actors
virtual void LineTraceWithFilter(TArray<FHitResult>& OutHitResults, const UWorld* World,
const FGameplayTargetDataFilterHandle FilterHandle, const FVector& Start,
const FVector& End, FName ProfileName, const FCollisionQueryParams Params);
virtual void AimWithPlayerController(const AActor* InSourceActor, FCollisionQueryParams Params,
const FVector& TraceStart, FVector& OutTraceEnd, bool bIgnorePitch = false);
virtual bool ClipCameraRayToAbilityRange(FVector CameraLocation, FVector CameraDirection, FVector AbilityCenter,
float AbilityRange, FVector& ClippedPosition);
virtual void StopTargeting();
protected:
// 检测终点, useful for debug drawing
FVector CurrentTraceEnd;
// 对准心Actor的引用
TArray<TWeakObjectPtr<AGameplayAbilityWorldReticle>> ReticleActors;
TArray<FHitResult> PersistentHitResults;
TArray<FHitResult> CurrentHitResults;
virtual FGameplayAbilityTargetDataHandle MakeTargetData(const TArray<FHitResult>& HitResults) const;
virtual TArray<FHitResult> PerformTrace(AActor* InSourceActor);
//实际的检测,由子类覆写。
virtual void DoTrace(TArray<FHitResult>& HitResults, const UWorld* World,
const FGameplayTargetDataFilterHandle FilterHandle, const FVector& Start, const FVector& End,
FName ProfileName, const FCollisionQueryParams Params) PURE_VIRTUAL(AUETA_Trace, return;);
virtual void ShowDebugTrace(TArray<FHitResult>& HitResults, EDrawDebugTrace::Type DrawDebugType,
float Duration = 2.0f) PURE_VIRTUAL(AUETA_Trace, return;);
/** 生成准心Actor */
virtual AGameplayAbilityWorldReticle* SpawnReticleActor(FVector Location, FRotator Rotation);
/**销毁所有准心Actor */
virtual void DestroyReticleActors();
public:
/**获取当前的hitresult */
UFUNCTION(BlueprintPure, Category = "GGA|TargetActor")
void GetCurrentHitResult(TArray<FHitResult>& HitResults);
};