KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
InteractableComponent.h
이 파일의 문서화 페이지로 가기
1// Copyright (c) 2025 Doppleddiggong. All rights reserved. Unauthorized copying, modification, or distribution of this file, via any medium is strictly prohibited. Proprietary and confidential.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Components/ActorComponent.h"
7#include "InteractableComponent.generated.h"
8
10#define INTERACT_WIDGET_PATH TEXT("/Game/CustomContents/UI/Widgets/WBP_InteractWidget.WBP_InteractWidget_C")
11
15UENUM(BlueprintType)
16enum class EInteractionType : uint8
17{
18 None UMETA(DisplayName = "None"),
19 PickUp UMETA(DisplayName = "Pick Up"), // 집어올리기
20 Button UMETA(DisplayName = "Button"), // 버튼 누르기
21 Kiosk UMETA(DisplayName = "Kiosk"),
22};
23
28DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnInteractionTriggered, AActor*, Interactor);
29
34DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnOutlineStateChanged, bool, bShouldShowOutline);
35
40UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
41class ONEPIECE_API UInteractableComponent : public UActorComponent
42{
43 GENERATED_BODY()
44
45public:
46 UInteractableComponent();
47
48protected:
49 virtual void BeginPlay() override;
50 virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
51 virtual void GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const override;
52
53private:
54 void InitDetectionRange();
55
56public:
57 // ========================================
58 // 상호작용 설정
59 // ========================================
60
62 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction")
63 EInteractionType InteractionType = EInteractionType::PickUp;
64
66 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction")
67 FString InteractionPrompt = TEXT("Press E to Interact");
68
70 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Interaction")
71 TObjectPtr<class UBoxComponent> DetectionRange;
72
74 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction")
75 float DetectionDistance = 250.0f;
76
78 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debug")
79 bool bShowDetectionDebug = true;
80
82 UPROPERTY(BlueprintReadOnly, Category = "Interaction")
83 bool bCanInteract = true;
84
85 // ========================================
86 // 델리게이트
87 // ========================================
88
90 UPROPERTY(BlueprintAssignable, Category = "Interaction")
91 FOnInteractionTriggered OnInteractionTriggered;
92
94 UPROPERTY(BlueprintAssignable, Category = "Interaction")
95 FOnOutlineStateChanged OnOutlineStateChanged;
96
97public:
98 UFUNCTION()
99 void OnRep_HoldingOwner();
100
105 UFUNCTION()
106 void OnRep_IsPickedUp();
107
108 // 현재 들고 있는 상태인지 확인
109 // BlueprintPure : 값만 반환, 상태 변경 없을 때 사용
110 UFUNCTION(BlueprintPure, Category = "Interaction")
111 FORCEINLINE bool IsPickedUp() const {return bIsPickedUp;}
112
113 // 물체 집어올림
114 UFUNCTION(BlueprintCallable, Category = "Interaction")
115 void PickUp(class AActor* NewHoldingOwner);
116
122 UFUNCTION(Server, Reliable, WithValidation)
123 void Server_PickUp(class AActor* NewHoldingOwner);
124
125 // 물체 놓음
126 UFUNCTION(BlueprintCallable, Category = "Interaction")
127 void Drop();
128
134 UFUNCTION(Server, Reliable, WithValidation)
135 void Server_Drop();
136
137 // 디버그 정보 표시 (타겟팅 중일 때)
138 UFUNCTION(BlueprintCallable, Category = "Debug")
139 void ShowDebugInfo(AActor* ViewerActor);
140
141 // ========================================
142 // 범용 상호작용
143 // ========================================
144
146 UFUNCTION(BlueprintCallable, Category = "Interaction")
147 void TriggerInteraction(AActor* Interactor);
148
154 UFUNCTION(BlueprintCallable, Category = "Interaction")
155 void SetOutlineState(bool bEnabled);
156
157public:
158 // Interaction
159 UPROPERTY(ReplicatedUsing=OnRep_HoldingOwner)
160 AActor* HoldingOwner;
166 UPROPERTY(ReplicatedUsing=OnRep_IsPickedUp, BlueprintReadOnly, Category = "Interaction")
167 bool bIsPickedUp = false;
168
169
170protected:
171 // ========================================
172 // Overlap 콜백 (InteractionSystem 등록)
173 // ========================================
174
175 UFUNCTION()
176 void OnDetectionBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
177 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
178 bool bFromSweep, const FHitResult& SweepResult);
179
180 UFUNCTION()
181 void OnDetectionEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
182 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
183
184 // ========================================
185 // Internal
186 // ========================================
187
189 bool bOriginalSimulatePhysics = false;
190
192 TEnumAsByte<ECollisionEnabled::Type> OriginalCollisionType;
193
194protected:
195 // Owner Actor의 PrimitiveComponent 찾기
196 // UPrimitiveComponent : 물리/충돌/렌더링을 가진 컴포넌트
197 // USceneComponent의 하위에 존재
198 // 컴포넌트가 붙는 액터의 Mesh를 가져오는 역할
199 UPrimitiveComponent* GetOwnerPrimitiveComponent() const;
200
201
202
203#pragma region Widget
204public:
205 void InitWidget(class UWidgetComponent* InWidgetComp);
206 void UpdateInteractPrompt(const FString& NewPrompt);
207
208 bool IsWidgetShowEnable(const class ACharacter* Character) const;
209
212 UFUNCTION(BlueprintCallable, Category = "Interaction")
213 void SetWidgetVisibility(bool bVisible);
214
215 // ========================================
216 // 상호작용 위젯
217 // ========================================
218
219private:
221 UFUNCTION(BlueprintCallable, Category = "Interaction")
222 void ShowInteractWidget();
223
225 UFUNCTION(BlueprintCallable, Category = "Interaction")
226 void HideInteractWidget();
227
229 void BillboardInteractWidget();
230
231private:
233 UPROPERTY()
234 TObjectPtr<class UWidgetComponent> WidgetComp;
235
236#pragma endregion
237};
EInteractionType
상호작용 타입 정의
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnInteractionTriggered, AActor *, Interactor)
상호작용 델리게이트