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

#include <InteractionComponent.h>

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

Public 멤버 함수

 UInteractionComponent ()
 
bool TryInteract ()
 
AInputResponsive * GetInteractionTarget () const
 

Public 속성

FOnInteractionFocusChanged OnInteractionFocusEntered
 
FOnInteractionFocusChanged OnInteractionFocusExited
 

Protected 멤버 함수

virtual void BeginPlay () override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 

Protected 속성

float TraceDistance = 5000.0f
 

Private 멤버 함수

AInputResponsive * FindInteractionTarget () const
 
void UpdateInteractionTarget ()
 
void SetInteractionTarget (AInputResponsive *NewTarget)
 
void HandleInteractionFocusEntered (AInputResponsive *Target)
 
void HandleInteractionFocusExited (AInputResponsive *Target)
 
void HandleTargetEndPlay (AActor *Actor, EEndPlayReason::Type EndPlayReason)
 

Private 속성

TWeakObjectPtr< AInputResponsive > InteractionTarget
 
TWeakObjectPtr< UUserWidgetBase > ActiveInteractionWidget
 
FTimerHandle InteractionUpdateTimer
 

상세한 설명

플레이어 카메라의 상호작용 대상을 탐색하고 대상 변경 시에만 시선 진입·이탈을 알립니다.

생성자 & 소멸자 문서화

◆ UInteractionComponent()

UInteractionComponent::UInteractionComponent ( )

Tick 대신 타이머로 시선 대상을 갱신합니다.

24{
25 PrimaryComponentTick.bCanEverTick = false;
26}

멤버 함수 문서화

◆ BeginPlay()

void UInteractionComponent::BeginPlay ( )
overrideprotectedvirtual
30{
31 Super::BeginPlay();
32 UWorld* World = GetWorld();
33
34 if (! World)
35 {
36 return;
37 }
38
39 // 빙의와 카메라 초기화 이후부터 초당 20회 판정합니다.
40 World->GetTimerManager().SetTimer(InteractionUpdateTimer, this, &ThisClass::UpdateInteractionTarget, 0.05f, true);
41}
FTimerHandle InteractionUpdateTimer
Definition InteractionComponent.h:75

다음을 참조함 : InteractionUpdateTimer.

◆ EndPlay()

void UInteractionComponent::EndPlay ( const EEndPlayReason::Type  EndPlayReason)
overrideprotectedvirtual
45{
46 if (UWorld* World = GetWorld())
47 {
48 World->GetTimerManager().ClearTimer(InteractionUpdateTimer);
49 }
50
51 SetInteractionTarget(nullptr);
52 Super::EndPlay(EndPlayReason);
53}
void SetInteractionTarget(AInputResponsive *NewTarget)
Definition InteractionComponent.cpp:180

다음을 참조함 : InteractionUpdateTimer, SetInteractionTarget().

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

◆ FindInteractionTarget()

AInputResponsive * UInteractionComponent::FindInteractionTarget ( ) const
private

카메라 레이에 처음 맞은 대상의 플레이어 거리·시선 각도·수평 방향·상호작용 조건을 검사합니다.

63{
64 const ACharacterBase* Character = Cast<ACharacterBase>(GetOwner());
65 const UWorld* World = GetWorld();
66
67 if (IsValid(Character) == false || World == nullptr || TraceDistance < KINDA_SMALL_NUMBER)
68 {
69 return nullptr;
70 }
71
72 const APlayerController* PlayerController = Cast<APlayerController>(Character->GetController());
73
74 if (IsValid(PlayerController) == false)
75 {
76 return nullptr;
77 }
78
79 FVector ViewLocation;
80 FRotator ViewRotation;
81 PlayerController->GetPlayerViewPoint(ViewLocation, ViewRotation);
82 const FVector InteractionRayDirection = ViewRotation.Vector();
83 FCollisionQueryParams QueryParams(NAME_None, false, Character);
84 TArray<AActor*> AttachedActors;
85 Character->GetAttachedActors(AttachedActors, true, true);
86 QueryParams.AddIgnoredActors(AttachedActors);
87 FHitResult Hit;
88
89 if (World->LineTraceSingleByChannel(Hit, ViewLocation, ViewLocation + InteractionRayDirection * TraceDistance, CCHANNEL_INTERACTION, QueryParams) == false)
90 {
91 return nullptr;
92 }
93
94 AInputResponsive* Target = Cast<AInputResponsive>(Hit.GetActor());
95
96 if (IsValid(Target) == false || Target->CanReceiveInput(GetOwner()) == false)
97 {
98 return nullptr;
99 }
100
101 const FVector TargetLocation = Target->GetActorLocation();
102 const float MaxDistance = Target->GetMaxInteractionDistance();
103
104 if (MaxDistance < KINDA_SMALL_NUMBER || (TargetLocation - Character->GetActorLocation()).SizeSquared() > FMath::Square(MaxDistance))
105 {
106 return nullptr;
107 }
108
109 const FVector DirectionToTarget = TargetLocation - ViewLocation;
110
111 if (DirectionToTarget.SizeSquared() < KINDA_SMALL_NUMBER)
112 {
113 return nullptr;
114 }
115
116 const double AllowedAngle = FMath::Clamp(FMath::Abs(static_cast<double>(Target->GetMaxInteractionAngle())), 0.0, 180.0);
117 const double ViewDot = FVector::DotProduct(InteractionRayDirection, DirectionToTarget.GetSafeNormal());
118 const double ViewAngle = FMath::RadiansToDegrees(FMath::Acos(FMath::Clamp(ViewDot, -1.0, 1.0)));
119
120 if (ViewAngle > AllowedAngle)
121 {
122 return nullptr;
123 }
124
125 const double AllowedFacingAngle = FMath::Clamp(FMath::Abs(static_cast<double>(Target->GetMaxFacingAngle())), 0.0, 180.0);
126
127 if (AllowedFacingAngle >= 180.0)
128 {
129 return Target;
130 }
131
132 const FVector Forward2D = Target->GetActorForwardVector().GetSafeNormal2D();
133 const FVector Ray2D = InteractionRayDirection.GetSafeNormal2D();
134
135 if (Forward2D.SizeSquared() < KINDA_SMALL_NUMBER || Ray2D.SizeSquared() < KINDA_SMALL_NUMBER)
136 {
137 return nullptr;
138 }
139
140 const double FacingDot = FVector::DotProduct(Forward2D, Ray2D);
141 const double FacingAngle = FMath::RadiansToDegrees(FMath::Acos(FMath::Clamp(FacingDot, -1.0, 1.0)));
142 return FacingAngle > AllowedFacingAngle ? nullptr : Target;
143}
#define CCHANNEL_INTERACTION
Definition CK_Collision.h:10
Definition CharacterBase.h:21
Definition InputResponsive.h:16
FORCEINLINE float GetMaxInteractionDistance() const
Definition InputResponsive.h:42
bool CanReceiveInput(AActor *Caller) const
Definition InputResponsive.cpp:20
FORCEINLINE float GetMaxInteractionAngle() const
Definition InputResponsive.h:45
FORCEINLINE float GetMaxFacingAngle() const
Definition InputResponsive.h:48
float TraceDistance
Definition InteractionComponent.h:70

다음을 참조함 : AInputResponsive::CanReceiveInput(), CCHANNEL_INTERACTION, AInputResponsive::GetMaxFacingAngle(), AInputResponsive::GetMaxInteractionAngle(), AInputResponsive::GetMaxInteractionDistance(), TraceDistance.

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

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

◆ GetInteractionTarget()

AInputResponsive * UInteractionComponent::GetInteractionTarget ( ) const

마지막 시선 갱신에서 상호작용 가능한 것으로 판정한 대상을 반환합니다.

57{
58 return InteractionTarget.Get();
59}
TWeakObjectPtr< AInputResponsive > InteractionTarget
Definition InteractionComponent.h:73

다음을 참조함 : InteractionTarget.

◆ HandleInteractionFocusEntered()

void UInteractionComponent::HandleInteractionFocusEntered ( AInputResponsive *  Target)
private

시선 진입 시 설정된 UIContext로 위젯을 등록하고 BP에 알립니다.

223{
224 const UInteractabilityComponent* Interactability = IsValid(Target) ? Target->FindComponentByClass<UInteractabilityComponent>() : nullptr;
225 const UInteractionSettings* Settings = GetDefault<UInteractionSettings>();
226 const FUIContext Context = Settings->GetInteractionMessageWidgetContext();
227
228 if (IsValid(Interactability) && Interactability->ShouldShowInteractionMessage() && Context.IsValid(UInteractionMessage::StaticClass()))
229 {
231 const FText Message = Interactability->GetInteractionMessage();
232 UInteractionMessage* Widget;
233
234 if (Subsystem)
235 {
236 UUILayer* OutLayer = nullptr;
237 Widget = Cast<UInteractionMessage>(Subsystem->PushWidget(Context, GetOwner(), OutLayer));
238 }
239 else
240 {
241 Widget = nullptr;
242 }
243
244 if (IsValid(Target) && InteractionTarget.Get() == Target)
245 {
247
248 if (IsValid(Widget))
249 {
250 Widget->SetMessage(Message);
251 }
252 }
253 else
254 {
255 if (IsValid(Widget))
256 {
257 Subsystem->PopWidget(Widget);
258 }
259 }
260 }
261
262 if (IsValid(Target) && InteractionTarget.Get() == Target)
263 {
264 OnInteractionFocusEntered.Broadcast(Target);
265 }
266}
static UUIManagementSubsystem * GetUIManagementSubsystem(const UObject *WorldContextObject)
Definition CK_BPFunctionLibrary.cpp:204
Definition InteractabilityComponent.h:15
FORCEINLINE bool ShouldShowInteractionMessage() const
Definition InteractabilityComponent.h:27
FORCEINLINE const FText & GetInteractionMessage() const
Definition InteractabilityComponent.h:34
FOnInteractionFocusChanged OnInteractionFocusEntered
Definition InteractionComponent.h:61
TWeakObjectPtr< UUserWidgetBase > ActiveInteractionWidget
Definition InteractionComponent.h:74
Definition InteractionMessage.h:15
void SetMessage(const FText &Message)
Definition InteractionMessage.cpp:9
Definition InteractionSettings.h:13
FUIContext GetInteractionMessageWidgetContext() const
Definition InteractionSettings.h:23
Definition UILayer.h:14
Definition UIManagementSubsystem.h:28
UUserWidgetBase * PushWidget(const FUIContext &Context, AActor *OwningActor, UUILayer *&OutLayer, UPanelWidget *ParentPanel=nullptr)
Definition UIManagementSubsystem.cpp:299
bool PopWidget(UUserWidgetBase *Widget)
Definition UIManagementSubsystem.cpp:406
Definition UIContext.h:10
bool IsValid(const UStruct *BaseClass) const
Definition UIContext.h:14

다음을 참조함 : ActiveInteractionWidget, UInteractabilityComponent::GetInteractionMessage(), UInteractionSettings::GetInteractionMessageWidgetContext(), UCK_BPFunctionLibrary::GetUIManagementSubsystem(), InteractionTarget, FUIContext::IsValid(), OnInteractionFocusEntered, UUIManagementSubsystem::PopWidget(), UUIManagementSubsystem::PushWidget(), UInteractionMessage::SetMessage(), UInteractabilityComponent::ShouldShowInteractionMessage().

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

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

◆ HandleInteractionFocusExited()

void UInteractionComponent::HandleInteractionFocusExited ( AInputResponsive *  Target)
private

시선 이탈 시 이 컴포넌트가 등록한 위젯을 해제하고 BP에 알립니다.

270{
273
274 if (IsValid(Widget))
275 {
277 Subsystem->PopWidget(Widget);
278 }
279
280 OnInteractionFocusExited.Broadcast(Target);
281}
FOnInteractionFocusChanged OnInteractionFocusExited
Definition InteractionComponent.h:65
Definition UserWidgetBase.h:35

다음을 참조함 : ActiveInteractionWidget, UCK_BPFunctionLibrary::GetUIManagementSubsystem(), OnInteractionFocusExited, UUIManagementSubsystem::PopWidget().

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

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

◆ HandleTargetEndPlay()

void UInteractionComponent::HandleTargetEndPlay ( AActor *  Actor,
EEndPlayReason::Type  EndPlayReason 
)
private

시선 대상이 제거되거나 레벨에서 내려갈 때 이탈 표시를 정리합니다.

285{
286 if (InteractionTarget.Get() != Actor)
287 {
288 return;
289 }
290
291 SetInteractionTarget(nullptr);
292}

다음을 참조함 : InteractionTarget, SetInteractionTarget().

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

◆ SetInteractionTarget()

void UInteractionComponent::SetInteractionTarget ( AInputResponsive *  NewTarget)
private

동일 대상은 무시하고 이전 대상 이탈 후 새 대상 진입을 통지합니다.

181{
182 if (InteractionTarget.Get() == NewTarget && InteractionTarget.IsStale() == false)
183 {
184 return;
185 }
186
187 AInputResponsive* PreviousTarget = InteractionTarget.Get();
188 const bool bHadTarget = InteractionTarget.IsExplicitlyNull() == false;
189 InteractionTarget = NewTarget;
190
191 if (IsValid(PreviousTarget))
192 {
193 PreviousTarget->OnEndPlay.RemoveDynamic(this, &ThisClass::HandleTargetEndPlay);
194 }
195
196 if (bHadTarget)
197 {
198 HandleInteractionFocusExited(PreviousTarget);
199 }
200
201 if (IsValid(PreviousTarget))
202 {
203 IInteractableInterface::Execute_OnInteractionFocusExited(PreviousTarget, GetOwner());
204 }
205
206 // 이탈 BP에서 대상을 제거하거나 바꾼 경우에는 진입을 통지하지 않습니다.
207 if (! IsValid(NewTarget) || InteractionTarget.Get() != NewTarget)
208 {
209 return;
210 }
211
212 NewTarget->OnEndPlay.AddDynamic(this, &ThisClass::HandleTargetEndPlay);
214
215 if (IsValid(NewTarget) && InteractionTarget.Get() == NewTarget)
216 {
217 IInteractableInterface::Execute_OnInteractionFocusEntered(NewTarget, GetOwner());
218 }
219}
void HandleInteractionFocusEntered(AInputResponsive *Target)
Definition InteractionComponent.cpp:222
void HandleInteractionFocusExited(AInputResponsive *Target)
Definition InteractionComponent.cpp:269

다음을 참조함 : HandleInteractionFocusEntered(), HandleInteractionFocusExited(), InteractionTarget.

다음에 의해서 참조됨 : EndPlay(), HandleTargetEndPlay(), UpdateInteractionTarget().

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

◆ TryInteract()

bool UInteractionComponent::TryInteract ( )

플레이어 IA에서 호출합니다. 현재 시선을 다시 검사한 뒤 대상의 상호작용을 시작합니다.

296{
298 AInputResponsive* Target = InteractionTarget.Get();
299
300 if (IsValid(Target))
301 {
302 const bool bStarted = Target->StartInteraction(GetOwner());
304 return bStarted;
305 }
306 else
307 {
308 return false;
309 }
310}
bool StartInteraction(AActor *Caller)
Definition InputResponsive.cpp:53
void UpdateInteractionTarget()
Definition InteractionComponent.cpp:146

다음을 참조함 : InteractionTarget, AInputResponsive::StartInteraction(), UpdateInteractionTarget().

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

◆ UpdateInteractionTarget()

void UInteractionComponent::UpdateInteractionTarget ( )
private

현재 시선으로 대상을 다시 판정합니다.

147{
149
150#if WITH_EDITOR
151 const ACharacterBase* Character = Cast<ACharacterBase>(GetOwner());
152 const APlayerController* PlayerController = IsValid(Character) ? Cast<APlayerController>(Character->GetController()) : nullptr;
153
154 if (GetDefault<UInteractionSettings>()->ShouldDrawInteractionRay() && GetWorld() && IsValid(PlayerController) && TraceDistance > 0.0f)
155 {
156 FVector ViewLocation;
157 FRotator ViewRotation;
158 PlayerController->GetPlayerViewPoint(ViewLocation, ViewRotation);
159
160 // 판정 주기 동안 표시하며, 거리·각도·입력 조건을 모두 통과해야 초록색입니다.
161 DrawDebugDirectionalArrow
162 (
163 GetWorld(),
164 ViewLocation,
165 ViewLocation + ViewRotation.Vector() * TraceDistance,
166 25.0f,
167 IsValid(Target) ? FColor::Green : FColor::Red,
168 false,
169 0.05f,
170 0,
171 2.0f
172 );
173 }
174#endif
175
176 SetInteractionTarget(Target);
177}
AInputResponsive * FindInteractionTarget() const
Definition InteractionComponent.cpp:62

다음을 참조함 : FindInteractionTarget(), SetInteractionTarget(), TraceDistance.

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

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

멤버 데이터 문서화

◆ ActiveInteractionWidget

TWeakObjectPtr<UUserWidgetBase> UInteractionComponent::ActiveInteractionWidget
private

◆ InteractionTarget

TWeakObjectPtr<AInputResponsive> UInteractionComponent::InteractionTarget
private

◆ InteractionUpdateTimer

FTimerHandle UInteractionComponent::InteractionUpdateTimer
private

다음에 의해서 참조됨 : BeginPlay(), EndPlay().

◆ OnInteractionFocusEntered

FOnInteractionFocusChanged UInteractionComponent::OnInteractionFocusEntered

상호작용 가능한 새 대상에 시선이 진입했을 때 한 번 알립니다.

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

◆ OnInteractionFocusExited

FOnInteractionFocusChanged UInteractionComponent::OnInteractionFocusExited

시선 대상에서 이탈했을 때 한 번 알립니다. 이미 제거된 대상은 nullptr일 수 있습니다.

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

◆ TraceDistance

float UInteractionComponent::TraceDistance = 5000.0f
protected

카메라 중앙에서 Interaction Trace를 수행할 최대 길이입니다. 대상별 허용 거리는 별도로 검사합니다.

다음에 의해서 참조됨 : FindInteractionTarget(), UpdateInteractionTarget().


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