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
 
bool ResolveCameraDensityTarget (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 멤버 함수

ITargetableInterface * GetCurrentTarget (const AMainPlayerCharacter *Player) const
 
TArray< ITargetableInterface * > GatherTargets (const AMainPlayerCharacter *Player) const
 
TArray< ITargetableInterface * > FilterVisibleTargets (const APlayerController *PC, const TArray< ITargetableInterface * > &Candidates) const
 
ITargetableInterface * PickDensityCenterTarget (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
171{
172 TArray<ITargetableInterface*> Result;
173
174 if (Player == nullptr)
175 {
176 return Result;
177 }
178
179 const FVector PlayerLocation = Player->GetActorLocation();
180 const float RangeSq = FMath::Square(FallbackSearchRange);
181
182 for (ITargetableInterface* Targetable : Candidates)
183 {
184 if (Targetable == nullptr)
185 {
186 continue;
187 }
188
189 const float DistSq = FVector::DistSquared2D(PlayerLocation, Targetable->GetTargetedActorLocation());
190
191 if (DistSq <= RangeSq)
192 {
193 Result.Add(Targetable);
194 }
195 }
196
197 return Result;
198}
Definition TargetableInterface.h:20
float FallbackSearchRange
Definition TargetSelector.h:74

다음을 참조함 : FallbackSearchRange, Player, Targetable.

다음에 의해서 참조됨 : ResolveTarget().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ FilterVisibleTargets()

TArray< ITargetableInterface * > UTargetSelector::FilterVisibleTargets ( const APlayerController *  PC,
const TArray< ITargetableInterface * > &  Candidates 
) const
private
155{
156 TArray<ITargetableInterface*> Result;
157
158 for (ITargetableInterface* Targetable : Candidates)
159 {
161 {
162 Result.Add(Targetable);
163 }
164 }
165
166 return Result;
167}
bool IsTargetInCameraView(const APlayerController *PC, ITargetableInterface *Targetable) const
Definition TargetSelector.cpp:308

다음을 참조함 : IsTargetInCameraView(), Targetable.

다음에 의해서 참조됨 : ResolveCameraDensityTarget(), ResolveTarget().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ GatherTargets()

TArray< ITargetableInterface * > UTargetSelector::GatherTargets ( const AMainPlayerCharacter *  Player) const
private
109{
110 TArray<ITargetableInterface*> Targets;
111
112 if (Player == nullptr || Player->GetWorld() == nullptr)
113 {
114 return Targets;
115 }
116
117 UStageSubsystem* StageSubsystem = Player->GetWorld()->GetSubsystem<UStageSubsystem>();
118
119 if (StageSubsystem == nullptr)
120 {
121 return Targets;
122 }
123
124 TargetableQuery Query = StageSubsystem->GetStageTargetableQueryHandle();
125 TArray<ITargetableInterface*> RawTargets = Query.GetTargets();
126 APlayerController* PC = Cast<APlayerController>(Player->GetController());
127
128 for (ITargetableInterface* Targetable : RawTargets)
129 {
130 if (Targetable == nullptr || Targetable->IsTargetValid() == false || Targetable->IsTargetable() == false)
131 {
132 continue;
133 }
134
135 if (bUseLineOfSight && HasLineOfSight(PC, Targetable) == false)
136 {
137 continue;
138 }
139
140 const float DistSq = FVector::DistSquared2D(Player->GetActorLocation(), Targetable->GetTargetedActorLocation());
141
142 if (DistSq > FMath::Square(TargetSearchRange))
143 {
144 continue;
145 }
146
147 Targets.Add(Targetable);
148 }
149
150 return Targets;
151}
Definition StageSubsystem.h:102
TargetableQuery GetStageTargetableQueryHandle() const
Definition StageSubsystem.cpp:236
bool bUseLineOfSight
Definition TargetSelector.h:80
float TargetSearchRange
Definition TargetSelector.h:71
bool HasLineOfSight(const APlayerController *PC, ITargetableInterface *Targetable) const
Definition TargetSelector.cpp:270
Definition TargetableQuery.h:93
TArray< ITargetableInterface * > GetTargets() const
Definition TargetableQuery.h:107

다음을 참조함 : bUseLineOfSight, UStageSubsystem::GetStageTargetableQueryHandle(), TargetableQuery::GetTargets(), HasLineOfSight(), Player, Targetable, TargetSearchRange.

다음에 의해서 참조됨 : ResolveCameraDensityTarget(), ResolveTarget().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ GetCurrentTarget()

ITargetableInterface * UTargetSelector::GetCurrentTarget ( const AMainPlayerCharacter *  Player) const
private
90{
91 if (Player == nullptr)
92 {
93 return nullptr;
94 }
95
96 const UCameraTargetingComponent* TargetingComponent = Player->GetPlayerTargetingComponent();
97
98 if (TargetingComponent == nullptr || TargetingComponent->IsTargeting() == false)
99 {
100 return nullptr;
101 }
102
103 TScriptInterface<ITargetableInterface> CurrentTarget = TargetingComponent->GetCurrentTarget();
104 return CurrentTarget.GetInterface();
105}
Definition CameraTargetingComponent.h:22
TScriptInterface< ITargetableInterface > GetCurrentTarget() const
Definition CameraTargetingComponent.cpp:239
bool IsTargeting() const
Definition CameraTargetingComponent.cpp:218

다음을 참조함 : UCameraTargetingComponent::GetCurrentTarget(), UCameraTargetingComponent::IsTargeting(), Player.

다음에 의해서 참조됨 : ResolveTarget().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ HasLineOfSight()

bool UTargetSelector::HasLineOfSight ( const APlayerController *  PC,
ITargetableInterface *  Targetable 
) const
private
271{
272 if (PC == nullptr || PC->GetWorld() == nullptr || PC->PlayerCameraManager == nullptr || Targetable == nullptr)
273 {
274 return false;
275 }
276
277 FCollisionQueryParams Params(SCENE_QUERY_STAT(TargetSelector), false);
278
279 if (PC->GetPawn())
280 {
281 Params.AddIgnoredActor(PC->GetPawn());
282 }
283
284 TArray<FHitResult> HitResults;
285 const FVector TraceStart = PC->PlayerCameraManager->GetCameraLocation();
286 const FVector TraceEnd = Targetable->GetTargetedActorLocation();
287 PC->GetWorld()->LineTraceMultiByChannel(HitResults, TraceStart, TraceEnd, ECC_Visibility, Params);
288
289 for (const FHitResult& Hit : HitResults)
290 {
291 if (Hit.Component.IsValid() && Hit.Component->GetCollisionProfileName() == CPROFILE_CKPLAYERCAPSULE)
292 {
293 continue;
294 }
295
296 if (Hit.GetActor() == ITargetableInterface::AsActor(Targetable))
297 {
298 return true;
299 }
300
301 return false;
302 }
303
304 return true;
305}
#define CPROFILE_CKPLAYERCAPSULE
Definition CK_Collision.h:16
static AActor * AsActor(ITargetableInterface *Interface)
Definition TargetableInterface.cpp:24

다음을 참조함 : ITargetableInterface::AsActor(), CPROFILE_CKPLAYERCAPSULE, Targetable.

다음에 의해서 참조됨 : GatherTargets().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ IsTargetInCameraView()

bool UTargetSelector::IsTargetInCameraView ( const APlayerController *  PC,
ITargetableInterface *  Targetable 
) const
private
309{
310 if (PC == nullptr || PC->PlayerCameraManager == nullptr || Targetable == nullptr)
311 {
312 return false;
313 }
314
315 const FVector TargetLocation = Targetable->GetTargetedActorLocation();
316 const FVector ToTarget = TargetLocation - PC->PlayerCameraManager->GetCameraLocation();
317 const float ForwardDot = FVector::DotProduct(PC->PlayerCameraManager->GetCameraRotation().Vector(), ToTarget);
318
319 if (ForwardDot <= 0.0f)
320 {
321 return false;
322 }
323
324 FVector2D ScreenPosition;
325
326 if (PC->ProjectWorldLocationToScreen(TargetLocation, ScreenPosition) == false)
327 {
328 return false;
329 }
330
331 int32 ViewportSizeX = 0;
332 int32 ViewportSizeY = 0;
333 PC->GetViewportSize(ViewportSizeX, ViewportSizeY);
334
335 if (ViewportSizeX <= 0 || ViewportSizeY <= 0)
336 {
337 return false;
338 }
339
340 return ScreenPosition.X >= 0.0f && ScreenPosition.X <= ViewportSizeX && ScreenPosition.Y >= 0.0f && ScreenPosition.Y <= ViewportSizeY;
341}

다음을 참조함 : Targetable.

다음에 의해서 참조됨 : FilterVisibleTargets().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ PickDensityCenterTarget()

ITargetableInterface * UTargetSelector::PickDensityCenterTarget ( const AMainPlayerCharacter *  Player,
const TArray< ITargetableInterface * > &  Candidates 
) const
private
202{
203 if (Player == nullptr || Candidates.IsEmpty())
204 {
205 return nullptr;
206 }
207
208 ITargetableInterface* BestTarget = nullptr;
209 int32 BestNeighborCount = INDEX_NONE;
210 float BestDistanceToClusterCenterSq = TNumericLimits<float>::Max();
211 float BestDistanceToPlayerSq = TNumericLimits<float>::Max();
212 const float DensityRadiusSq = FMath::Square(DensityRadius);
213 const FVector PlayerLocation = Player->GetActorLocation();
214
215 for (ITargetableInterface* Candidate : Candidates)
216 {
217 if (Candidate == nullptr)
218 {
219 continue;
220 }
221
222 const FVector CandidateLocation = Candidate->GetTargetedActorLocation();
223 FVector ClusterCenter = FVector::ZeroVector;
224 int32 NeighborCount = 0;
225
226 for (ITargetableInterface* Other : Candidates)
227 {
228 if (Other == nullptr)
229 {
230 continue;
231 }
232
233 const FVector OtherLocation = Other->GetTargetedActorLocation();
234
235 if (FVector::DistSquared2D(CandidateLocation, OtherLocation) > DensityRadiusSq)
236 {
237 continue;
238 }
239
240 ClusterCenter += OtherLocation;
241 NeighborCount++;
242 }
243
244 if (NeighborCount <= 0)
245 {
246 continue;
247 }
248
249 ClusterCenter /= static_cast<float>(NeighborCount);
250
251 const float DistanceToClusterCenterSq = FVector::DistSquared2D(CandidateLocation, ClusterCenter);
252 const float DistanceToPlayerSq = FVector::DistSquared2D(CandidateLocation, PlayerLocation);
253 const bool bHasMoreNeighbors = NeighborCount > BestNeighborCount;
254 const bool bCloserToClusterCenter = NeighborCount == BestNeighborCount && DistanceToClusterCenterSq < BestDistanceToClusterCenterSq;
255 const bool bCloserToPlayer = NeighborCount == BestNeighborCount && FMath::IsNearlyEqual(DistanceToClusterCenterSq, BestDistanceToClusterCenterSq) && DistanceToPlayerSq < BestDistanceToPlayerSq;
256
257 if (bHasMoreNeighbors || bCloserToClusterCenter || bCloserToPlayer)
258 {
259 BestTarget = Candidate;
260 BestNeighborCount = NeighborCount;
261 BestDistanceToClusterCenterSq = DistanceToClusterCenterSq;
262 BestDistanceToPlayerSq = DistanceToPlayerSq;
263 }
264 }
265
266 return BestTarget;
267}
float DensityRadius
Definition TargetSelector.h:77

다음을 참조함 : DensityRadius, Player.

다음에 의해서 참조됨 : ResolveCameraDensityTarget(), ResolveTarget().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ ResolveCameraDensityTarget()

bool UTargetSelector::ResolveCameraDensityTarget ( const AMainPlayerCharacter *  Player,
FTargetSelectionResult &  OutResult 
) const

화면에 보이는 유효한 적만 밀집 평가하며, 화면 밖 대상이나 무기로 대체하지 않습니다.

60{
61 OutResult = FTargetSelectionResult();
62
63 if (Player == nullptr)
64 {
65 return false;
66 }
67
68 const APlayerController* PC = Cast<APlayerController>(Player->GetController());
69 TArray<ITargetableInterface*> Candidates = FilterVisibleTargets(PC, GatherTargets(Player));
70 Candidates.RemoveAll([](ITargetableInterface* Candidate)
71 {
72 return Cast<AEnemyCharacterBase>(ITargetableInterface::AsActor(Candidate)) == nullptr;
73 });
75
76 if (Target == nullptr)
77 {
78 return false;
79 }
80
81 OutResult.bHasTarget = true;
83 OutResult.TargetLocation = Target->GetTargetedActorLocation();
84 OutResult.TargetDistance = FVector::Dist2D(Player->GetActorLocation(), OutResult.TargetLocation);
85 return true;
86}
virtual FVector GetTargetedActorLocation()
Definition TargetableInterface.cpp:95
TArray< ITargetableInterface * > FilterVisibleTargets(const APlayerController *PC, const TArray< ITargetableInterface * > &Candidates) const
Definition TargetSelector.cpp:154
TArray< ITargetableInterface * > GatherTargets(const AMainPlayerCharacter *Player) const
Definition TargetSelector.cpp:108
ITargetableInterface * PickDensityCenterTarget(const AMainPlayerCharacter *Player, const TArray< ITargetableInterface * > &Candidates) const
Definition TargetSelector.cpp:201
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

다음을 참조함 : ITargetableInterface::AsActor(), FTargetSelectionResult::bHasTarget, FilterVisibleTargets(), GatherTargets(), ITargetableInterface::GetTargetedActorLocation(), PickDensityCenterTarget(), Player, FTargetSelectionResult::TargetActor, FTargetSelectionResult::TargetDistance, FTargetSelectionResult::TargetLocation.

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ ResolveTarget()

bool UTargetSelector::ResolveTarget ( const AMainPlayerCharacter *  Player,
FTargetSelectionResult &  OutResult 
) const
17{
18 OutResult = FTargetSelectionResult();
19
20 if (Player == nullptr)
21 {
22 return false;
23 }
24
26
28 {
30 }
31
33 {
34 APlayerController* PC = Cast<APlayerController>(Player->GetController());
35 TArray<ITargetableInterface*> Candidates = GatherTargets(Player);
36 TArray<ITargetableInterface*> SelectedCandidates = FilterVisibleTargets(PC, Candidates);
37
38 if (SelectedCandidates.IsEmpty())
39 {
40 SelectedCandidates = FilterTargetsInPlayerRange(Player, Candidates);
41 }
42
43 Targetable = PickDensityCenterTarget(Player, SelectedCandidates);
44 }
45
46 if (Targetable == nullptr)
47 {
48 return true;
49 }
50
51 OutResult.bHasTarget = true;
53 OutResult.TargetLocation = Targetable->GetTargetedActorLocation();
54 OutResult.TargetDistance = FVector::Dist2D(Player->GetActorLocation(), OutResult.TargetLocation);
55 return true;
56}
ITargetableInterface * GetCurrentTarget(const AMainPlayerCharacter *Player) const
Definition TargetSelector.cpp:89
ETargetSelectionMode SelectionMode
Definition TargetSelector.h:68
TArray< ITargetableInterface * > FilterTargetsInPlayerRange(const AMainPlayerCharacter *Player, const TArray< ITargetableInterface * > &Candidates) const
Definition TargetSelector.cpp:170

다음을 참조함 : ITargetableInterface::AsActor(), FTargetSelectionResult::bHasTarget, CurrentTargetOnly, CurrentTargetOrDensity, FilterTargetsInPlayerRange(), FilterVisibleTargets(), GatherTargets(), GetCurrentTarget(), PickDensityCenterTarget(), Player, SelectionMode, Targetable, FTargetSelectionResult::TargetActor, FTargetSelectionResult::TargetDistance, FTargetSelectionResult::TargetLocation.

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

멤버 데이터 문서화

◆ bUseLineOfSight

bool UTargetSelector::bUseLineOfSight = true
protected

다음에 의해서 참조됨 : GatherTargets().

◆ DensityRadius

float UTargetSelector::DensityRadius = 350.0f
protected

다음에 의해서 참조됨 : PickDensityCenterTarget().

◆ FallbackSearchRange

float UTargetSelector::FallbackSearchRange = 2000.0f
protected

다음에 의해서 참조됨 : FilterTargetsInPlayerRange().

◆ SelectionMode

ETargetSelectionMode UTargetSelector::SelectionMode = ETargetSelectionMode::CurrentTargetOrDensity
protected

다음에 의해서 참조됨 : ResolveTarget().

◆ TargetSearchRange

float UTargetSelector::TargetSearchRange = 2000.0f
protected

다음에 의해서 참조됨 : GatherTargets().


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