Payback 0.0.1
CK Graduation Project
로딩중...
검색중...
일치하는것 없음
UTargetSelector 클래스 참조

#include <TargetSelector.h>

UTargetSelector에 대한 상속 다이어그램 :
Inheritance graph
UTargetSelector에 대한 협력 다이어그램:
Collaboration graph

Public 멤버 함수

bool ResolveTarget (const AMainPlayerCharacter *Player, FTargetSelectionResult &OutResult) const
 

Protected 속성

ETargetSelectionMode SelectionMode = ETargetSelectionMode::CurrentTargetOrDensity
 
float TargetSearchRange = 2000.0f
 
float FallbackSearchRange = 2000.0f
 
float DensityRadius = 350.0f
 
bool bUseLineOfSight = true
 

Private 멤버 함수

ITargetableInterfaceGetCurrentTarget (const AMainPlayerCharacter *Player) const
 
TArray< ITargetableInterface * > GatherTargets (const AMainPlayerCharacter *Player) const
 
TArray< ITargetableInterface * > FilterVisibleTargets (const APlayerController *PC, const TArray< ITargetableInterface * > &Candidates) const
 
ITargetableInterfacePickDensityCenterTarget (const AMainPlayerCharacter *Player, const TArray< ITargetableInterface * > &Candidates) const
 
TArray< ITargetableInterface * > FilterTargetsInPlayerRange (const AMainPlayerCharacter *Player, const TArray< ITargetableInterface * > &Candidates) const
 
bool HasLineOfSight (const APlayerController *PC, ITargetableInterface *Targetable) const
 
bool IsTargetInCameraView (const APlayerController *PC, ITargetableInterface *Targetable) const
 

멤버 함수 문서화

◆ FilterTargetsInPlayerRange()

TArray< ITargetableInterface * > UTargetSelector::FilterTargetsInPlayerRange ( const AMainPlayerCharacter Player,
const TArray< ITargetableInterface * > &  Candidates 
) const
private
140{
141 TArray<ITargetableInterface*> Result;
142
143 if (Player == nullptr)
144 {
145 return Result;
146 }
147
148 const FVector PlayerLocation = Player->GetActorLocation();
149 const float RangeSq = FMath::Square(FallbackSearchRange);
150
151 for (ITargetableInterface* Targetable : Candidates)
152 {
153 if (Targetable == nullptr)
154 {
155 continue;
156 }
157
158 const float DistSq = FVector::DistSquared2D(PlayerLocation, Targetable->GetTargetedActorLocation());
159
160 if (DistSq <= RangeSq)
161 {
162 Result.Add(Targetable);
163 }
164 }
165
166 return Result;
167}
Definition TargetableInterface.h:20
float FallbackSearchRange
Definition TargetSelector.h:71
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ FilterVisibleTargets()

TArray< ITargetableInterface * > UTargetSelector::FilterVisibleTargets ( const APlayerController *  PC,
const TArray< ITargetableInterface * > &  Candidates 
) const
private
124{
125 TArray<ITargetableInterface*> Result;
126
127 for (ITargetableInterface* Targetable : Candidates)
128 {
130 {
131 Result.Add(Targetable);
132 }
133 }
134
135 return Result;
136}
bool IsTargetInCameraView(const APlayerController *PC, ITargetableInterface *Targetable) const
Definition TargetSelector.cpp:277
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ GatherTargets()

TArray< ITargetableInterface * > UTargetSelector::GatherTargets ( const AMainPlayerCharacter Player) const
private
78{
79 TArray<ITargetableInterface*> Targets;
80
81 if (Player == nullptr || Player->GetWorld() == nullptr)
82 {
83 return Targets;
84 }
85
86 UStageManagementSubsystem* StageSubsystem = Player->GetWorld()->GetSubsystem<UStageManagementSubsystem>();
87
88 if (StageSubsystem == nullptr)
89 {
90 return Targets;
91 }
92
93 TargetableQuery Query = StageSubsystem->GetStageTargetableQueryHandle();
94 TArray<ITargetableInterface*> RawTargets = Query.GetTargets();
95 APlayerController* PC = Cast<APlayerController>(Player->GetController());
96
97 for (ITargetableInterface* Targetable : RawTargets)
98 {
99 if (Targetable == nullptr || Targetable->IsTargetValid() == false || Targetable->IsTargetable() == false)
100 {
101 continue;
102 }
103
104 if (bUseLineOfSight && HasLineOfSight(PC, Targetable) == false)
105 {
106 continue;
107 }
108
109 const float DistSq = FVector::DistSquared2D(Player->GetActorLocation(), Targetable->GetTargetedActorLocation());
110
111 if (DistSq > FMath::Square(TargetSearchRange))
112 {
113 continue;
114 }
115
116 Targets.Add(Targetable);
117 }
118
119 return Targets;
120}
Definition StageManagementSubsystem.h:147
TargetableQuery GetStageTargetableQueryHandle() const
Definition StageManagementSubsystem.cpp:280
bool bUseLineOfSight
Definition TargetSelector.h:77
float TargetSearchRange
Definition TargetSelector.h:68
bool HasLineOfSight(const APlayerController *PC, ITargetableInterface *Targetable) const
Definition TargetSelector.cpp:239
Definition TargetableQuery.h:92
TArray< ITargetableInterface * > GetTargets() const
Definition TargetableQuery.h:106
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ GetCurrentTarget()

ITargetableInterface * UTargetSelector::GetCurrentTarget ( const AMainPlayerCharacter Player) const
private
59{
60 if (Player == nullptr)
61 {
62 return nullptr;
63 }
64
65 const UCameraTargetingComponent* TargetingComponent = Player->GetPlayerTargetingComponent();
66
67 if (TargetingComponent == nullptr || TargetingComponent->IsTargeting() == false)
68 {
69 return nullptr;
70 }
71
72 TScriptInterface<ITargetableInterface> CurrentTarget = TargetingComponent->GetCurrentTarget();
73 return CurrentTarget.GetInterface();
74}
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ HasLineOfSight()

bool UTargetSelector::HasLineOfSight ( const APlayerController *  PC,
ITargetableInterface Targetable 
) const
private
240{
241 if (PC == nullptr || PC->GetWorld() == nullptr || PC->PlayerCameraManager == nullptr || Targetable == nullptr)
242 {
243 return false;
244 }
245
246 FCollisionQueryParams Params(SCENE_QUERY_STAT(TargetSelector), false);
247
248 if (PC->GetPawn())
249 {
250 Params.AddIgnoredActor(PC->GetPawn());
251 }
252
253 TArray<FHitResult> HitResults;
254 const FVector TraceStart = PC->PlayerCameraManager->GetCameraLocation();
255 const FVector TraceEnd = Targetable->GetTargetedActorLocation();
256 PC->GetWorld()->LineTraceMultiByChannel(HitResults, TraceStart, TraceEnd, ECC_Visibility, Params);
257
258 for (const FHitResult& Hit : HitResults)
259 {
260 if (Hit.Component.IsValid() && Hit.Component->GetCollisionProfileName() == CPROFILE_CKPLAYERCAPSULE)
261 {
262 continue;
263 }
264
265 if (Hit.GetActor() == ITargetableInterface::AsActor(Targetable))
266 {
267 return true;
268 }
269
270 return false;
271 }
272
273 return true;
274}
#define CPROFILE_CKPLAYERCAPSULE
Definition CK_Collision.h:15
static AActor * AsActor(ITargetableInterface *Interface)
Definition TargetableInterface.cpp:24
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ IsTargetInCameraView()

bool UTargetSelector::IsTargetInCameraView ( const APlayerController *  PC,
ITargetableInterface Targetable 
) const
private
278{
279 if (PC == nullptr || PC->PlayerCameraManager == nullptr || Targetable == nullptr)
280 {
281 return false;
282 }
283
284 const FVector TargetLocation = Targetable->GetTargetedActorLocation();
285 const FVector ToTarget = TargetLocation - PC->PlayerCameraManager->GetCameraLocation();
286 const float ForwardDot = FVector::DotProduct(PC->PlayerCameraManager->GetCameraRotation().Vector(), ToTarget);
287
288 if (ForwardDot <= 0.0f)
289 {
290 return false;
291 }
292
293 FVector2D ScreenPosition;
294
295 if (PC->ProjectWorldLocationToScreen(TargetLocation, ScreenPosition) == false)
296 {
297 return false;
298 }
299
300 int32 ViewportSizeX = 0;
301 int32 ViewportSizeY = 0;
302 PC->GetViewportSize(ViewportSizeX, ViewportSizeY);
303
304 if (ViewportSizeX <= 0 || ViewportSizeY <= 0)
305 {
306 return false;
307 }
308
309 return ScreenPosition.X >= 0.0f && ScreenPosition.X <= ViewportSizeX && ScreenPosition.Y >= 0.0f && ScreenPosition.Y <= ViewportSizeY;
310}
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ PickDensityCenterTarget()

ITargetableInterface * UTargetSelector::PickDensityCenterTarget ( const AMainPlayerCharacter Player,
const TArray< ITargetableInterface * > &  Candidates 
) const
private
171{
172 if (Player == nullptr || Candidates.IsEmpty())
173 {
174 return nullptr;
175 }
176
177 ITargetableInterface* BestTarget = nullptr;
178 int32 BestNeighborCount = INDEX_NONE;
179 float BestDistanceToClusterCenterSq = TNumericLimits<float>::Max();
180 float BestDistanceToPlayerSq = TNumericLimits<float>::Max();
181 const float DensityRadiusSq = FMath::Square(DensityRadius);
182 const FVector PlayerLocation = Player->GetActorLocation();
183
184 for (ITargetableInterface* Candidate : Candidates)
185 {
186 if (Candidate == nullptr)
187 {
188 continue;
189 }
190
191 const FVector CandidateLocation = Candidate->GetTargetedActorLocation();
192 FVector ClusterCenter = FVector::ZeroVector;
193 int32 NeighborCount = 0;
194
195 for (ITargetableInterface* Other : Candidates)
196 {
197 if (Other == nullptr)
198 {
199 continue;
200 }
201
202 const FVector OtherLocation = Other->GetTargetedActorLocation();
203
204 if (FVector::DistSquared2D(CandidateLocation, OtherLocation) > DensityRadiusSq)
205 {
206 continue;
207 }
208
209 ClusterCenter += OtherLocation;
210 NeighborCount++;
211 }
212
213 if (NeighborCount <= 0)
214 {
215 continue;
216 }
217
218 ClusterCenter /= static_cast<float>(NeighborCount);
219
220 const float DistanceToClusterCenterSq = FVector::DistSquared2D(CandidateLocation, ClusterCenter);
221 const float DistanceToPlayerSq = FVector::DistSquared2D(CandidateLocation, PlayerLocation);
222 const bool bHasMoreNeighbors = NeighborCount > BestNeighborCount;
223 const bool bCloserToClusterCenter = NeighborCount == BestNeighborCount && DistanceToClusterCenterSq < BestDistanceToClusterCenterSq;
224 const bool bCloserToPlayer = NeighborCount == BestNeighborCount && FMath::IsNearlyEqual(DistanceToClusterCenterSq, BestDistanceToClusterCenterSq) && DistanceToPlayerSq < BestDistanceToPlayerSq;
225
226 if (bHasMoreNeighbors || bCloserToClusterCenter || bCloserToPlayer)
227 {
228 BestTarget = Candidate;
229 BestNeighborCount = NeighborCount;
230 BestDistanceToClusterCenterSq = DistanceToClusterCenterSq;
231 BestDistanceToPlayerSq = DistanceToPlayerSq;
232 }
233 }
234
235 return BestTarget;
236}
float DensityRadius
Definition TargetSelector.h:74
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ ResolveTarget()

bool UTargetSelector::ResolveTarget ( const AMainPlayerCharacter Player,
FTargetSelectionResult OutResult 
) const
16{
17 OutResult = FTargetSelectionResult();
18
19 if (Player == nullptr)
20 {
21 return false;
22 }
23
25
27 {
29 }
30
32 {
33 APlayerController* PC = Cast<APlayerController>(Player->GetController());
34 TArray<ITargetableInterface*> Candidates = GatherTargets(Player);
35 TArray<ITargetableInterface*> SelectedCandidates = FilterVisibleTargets(PC, Candidates);
36
37 if (SelectedCandidates.IsEmpty())
38 {
39 SelectedCandidates = FilterTargetsInPlayerRange(Player, Candidates);
40 }
41
42 Targetable = PickDensityCenterTarget(Player, SelectedCandidates);
43 }
44
45 if (Targetable == nullptr)
46 {
47 return true;
48 }
49
50 OutResult.bHasTarget = true;
52 OutResult.TargetLocation = Targetable->GetTargetedActorLocation();
53 OutResult.TargetDistance = FVector::Dist2D(Player->GetActorLocation(), OutResult.TargetLocation);
54 return true;
55}
ITargetableInterface * GetCurrentTarget(const AMainPlayerCharacter *Player) const
Definition TargetSelector.cpp:58
TArray< ITargetableInterface * > FilterVisibleTargets(const APlayerController *PC, const TArray< ITargetableInterface * > &Candidates) const
Definition TargetSelector.cpp:123
TArray< ITargetableInterface * > GatherTargets(const AMainPlayerCharacter *Player) const
Definition TargetSelector.cpp:77
ETargetSelectionMode SelectionMode
Definition TargetSelector.h:65
TArray< ITargetableInterface * > FilterTargetsInPlayerRange(const AMainPlayerCharacter *Player, const TArray< ITargetableInterface * > &Candidates) const
Definition TargetSelector.cpp:139
ITargetableInterface * PickDensityCenterTarget(const AMainPlayerCharacter *Player, const TArray< ITargetableInterface * > &Candidates) const
Definition TargetSelector.cpp:170
Definition TargetSelector.h:26
float TargetDistance
Definition TargetSelector.h:40
TObjectPtr< AActor > TargetActor
Definition TargetSelector.h:34
bool bHasTarget
Definition TargetSelector.h:31
FVector TargetLocation
Definition TargetSelector.h:37
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

멤버 데이터 문서화

◆ bUseLineOfSight

bool UTargetSelector::bUseLineOfSight = true
protected

◆ DensityRadius

float UTargetSelector::DensityRadius = 350.0f
protected

◆ FallbackSearchRange

float UTargetSelector::FallbackSearchRange = 2000.0f
protected

◆ SelectionMode

ETargetSelectionMode UTargetSelector::SelectionMode = ETargetSelectionMode::CurrentTargetOrDensity
protected

◆ TargetSearchRange

float UTargetSelector::TargetSearchRange = 2000.0f
protected

이 클래스에 대한 문서화 페이지는 다음의 파일들로부터 생성되었습니다.: