KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
ABroadcastTrigger.cpp
이 파일의 문서화 페이지로 가기
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
4#include "ABroadcastTrigger.h"
5#include "Components/BoxComponent.h"
6#include "DrawDebugHelpers.h"
7#include "APlayerActor.h"
8#include "GameFramework/PlayerController.h"
9#include "GameLogging.h"
10
12{
13 PrimaryActorTick.bCanEverTick = true;
14 bReplicates = true;
15
16 // 루트 컴포넌트로 BoxComponent 생성
17 TriggerBox = CreateDefaultSubobject<UBoxComponent>(TEXT("TriggerBox"));
18 RootComponent = TriggerBox;
19
20 // 박스 크기 기본값 설정
21 TriggerBox->SetBoxExtent(FVector(100.0f, 100.0f, 100.0f));
22
23 // Overlap 이벤트 활성화
24 TriggerBox->SetGenerateOverlapEvents(true);
25 TriggerBox->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
26 TriggerBox->SetCollisionResponseToAllChannels(ECR_Ignore);
27 TriggerBox->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
28
29 // 초기값 설정
30 bIsTriggered = false;
31 bShowDebugBox = true;
32 DebugBoxColor = FColor::Green;
33}
34
36{
37 Super::BeginPlay();
38
39 if (TriggerBox)
40 TriggerBox->OnComponentBeginOverlap.AddDynamic(this, &ABroadcastTrigger::OnTriggerBeginOverlap);
41}
42
43void ABroadcastTrigger::Tick(float DeltaTime)
44{
45 Super::Tick(DeltaTime);
46
48 {
49 FVector BoxCenter = TriggerBox->GetComponentLocation();
50 FVector BoxExtent = TriggerBox->GetScaledBoxExtent();
51 FRotator BoxRotation = TriggerBox->GetComponentRotation();
52
53 // 디버그 박스 표시 (트리거 활성화 상태일 때만)
54 if (!bIsTriggered)
55 {
56 DrawDebugBox(
57 GetWorld(),
58 BoxCenter,
59 BoxExtent,
60 BoxRotation.Quaternion(),
62 false,
63 -1.0f,
64 0,
65 2.0f
66 );
67 }
68
69 // 트리거 정보를 텍스트로 표시
70 FString StatusText = bIsTriggered ? TEXT("[TRIGGERED]") : TEXT("[ACTIVE]");
71 FColor TextColor = bIsTriggered ? FColor::Red : FColor::Green;
72
73 FVector TextLocation = BoxCenter + FVector(0.0f, 0.0f, BoxExtent.Z + 50.0f);
74
75 // 상태 표시
76 DrawDebugString(
77 GetWorld(),
78 TextLocation,
79 StatusText,
80 nullptr,
81 TextColor,
82 0.0f,
83 true,
84 1.2f
85 );
86 }
87}
88
90 UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
91 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
92 bool bFromSweep, const FHitResult& SweepResult)
93{
94 // 이미 트리거되었으면 무시
95 if (bIsTriggered)
96 return;
97
98 // PlayerActor인지 확인
99 APlayerActor* PlayerActor = Cast<APlayerActor>(OtherActor);
100 if (PlayerActor)
101 {
102 OnActivate();
103
104 bIsTriggered = true;
105 }
106}
107
109{
110 PRINT_STRING(TEXT("ABroadcastTrigger Activated"));
111}
Declares the player-controlled character actor.
YiSan 전반에서 사용하는 공용 인터페이스를 선언합니다.
#define PRINT_STRING(fmt,...)
Definition GameLogging.h:45
TObjectPtr< class UBoxComponent > TriggerBox
트리거 영역을 정의하는 박스 컴포넌트
bool bIsTriggered
트리거 활성화 상태 (false = 활성화, true = 비활성화)
virtual void Tick(float DeltaTime) override
virtual void BeginPlay() override
FColor DebugBoxColor
디버그 박스 색상
virtual void OnActivate_Implementation()
bool bShowDebugBox
디버그 드로우 표시 여부
void OnTriggerBeginOverlap(UPrimitiveComponent *OverlappedComponent, AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
트리거 박스 Overlap 시작 이벤트 핸들러
Main character driven directly by the player.