KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
AGate.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#include "AGate.h"
4
5#include "UBroadcastManager.h"
6
7#include "Components/BoxComponent.h"
8#include "Components/StaticMeshComponent.h"
9#include "GameFramework/Pawn.h"
10#include "Onepiece/Onepiece.h"
11
19{
20 RootComp = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
21 RootComponent = RootComp;
22
23 BoxCollision = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxCollision"));
24 BoxCollision->SetupAttachment(RootComponent);
25
26 BoxCollision->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
27 BoxCollision->SetCollisionObjectType(ECollisionChannel::ECC_WorldDynamic);
28 BoxCollision->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
29 BoxCollision->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap);
30
31 BoxCollision->OnComponentBeginOverlap.AddDynamic(this, &AGate::OnOverlapBegin);
32 BoxCollision->OnComponentEndOverlap.AddDynamic(this, &AGate::OnOverlapEnd);
33
34 Door_Left = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Door_Left"));
35 Door_Left->SetupAttachment(RootComponent);
36
37 Door_Right = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Door_Right"));
38 Door_Right->SetupAttachment(RootComponent);
39
40 bIsOpen = false;
41 GateID = -1;
42
43 PrimaryActorTick.bCanEverTick = false;
44}
45
48{
49 Super::BeginPlay();
50
51 if (auto EventManager = UBroadcastManager::Get(this))
52 {
53 EventManager->OnDoorMessage.AddDynamic(this, &AGate::OnDoorMessage);
54 }
55}
56
62void AGate::OnDoorMessage(const int32 InGateID, const bool Open, AActor* EventInstigator)
63{
64 if ( InGateID != this->GateID)
65 {
66 // 나한테 명령한거 아님
67 return;
68 }
69
70 if ( Open == this->bIsOpen)
71 {
72 // 내가 또 해야하는거 아님
73 return;
74 }
75
76 if (Open)
77 {
78 OpenDoor();
79 }
80 else
81 {
82 CloseDoor();
83 }
84}
85
88{
89 if (bIsOpen == true)
90 return;
91
92 bIsOpen = true;
94}
95
98{
99 if (bIsOpen == false)
100 return;
101
102 bIsOpen = false;
104}
105
111bool AGate::IsPlayerActor(const AActor* OtherActor) const
112{
113 if ( OtherActor == nullptr)
114 return false;
115
116 if ( OtherActor == this)
117 return false;
118
119 if ( OtherActor->ActorHasTag(GameTags::Player) == false)
120 return false;
121
122 return true;
123}
124
126void AGate::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
127{
128 if (IsPlayerActor(OtherActor))
129 {
130 if ( auto Pawn = Cast<APawn>(OtherActor) )
131 {
132 if ( OverlappingPawns.Contains(Pawn) == false )
133 OverlappingPawns.Add(Pawn);
134 }
135
136 OpenDoor();
137 }
138}
139
141void AGate::OnOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
142{
143 if (IsPlayerActor(OtherActor))
144 {
145 if ( auto Pawn = Cast<APawn>(OtherActor) )
146 OverlappingPawns.Remove(Pawn);
147
148 if (OverlappingPawns.Num() == 0)
149 CloseDoor();
150 }
151}
출입문 개폐를 담당하는 게이트 액터를 선언합니다.
bool IsPlayerActor(const AActor *OtherActor) const
겹친 액터가 플레이어인지 판별합니다.
Definition AGate.cpp:111
virtual void BeginPlay() override
브로드캐스트 구독 등 초기화를 수행합니다.
Definition AGate.cpp:47
AGate()
컴포넌트 계층을 구성하는 기본 생성자입니다.
Definition AGate.cpp:18
void PlayCloseDoorAnimation()
문을 닫을 때 재생할 블루프린트 애니메이션입니다.
int32 GateID
Definition AGate.h:73
TObjectPtr< class USceneComponent > RootComp
Definition AGate.h:61
TObjectPtr< class UBoxComponent > BoxCollision
Definition AGate.h:70
void OpenDoor()
문을 여는 동작을 트리거합니다.
Definition AGate.cpp:87
bool bIsOpen
Definition AGate.h:77
void OnDoorMessage(int32 InGateID, bool Open, AActor *EventInstigator)
외부 시스템에서 전달된 개폐 메시지를 처리합니다.
Definition AGate.cpp:62
void PlayOpenDoorAnimation()
문을 열 때 재생할 블루프린트 애니메이션입니다.
TObjectPtr< class UStaticMeshComponent > Door_Right
Definition AGate.h:67
void CloseDoor()
문을 닫는 동작을 트리거합니다.
Definition AGate.cpp:97
void OnOverlapEnd(UPrimitiveComponent *OverlappedComp, AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex)
플레이어가 감지 범위에서 벗어났을 때 호출됩니다.
Definition AGate.cpp:141
void OnOverlapBegin(UPrimitiveComponent *OverlappedComp, AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
플레이어가 감지 범위에 들어왔을 때 호출됩니다.
Definition AGate.cpp:126
TArray< TObjectPtr< class APawn > > OverlappingPawns
Definition AGate.h:80
TObjectPtr< class UStaticMeshComponent > Door_Left
Definition AGate.h:64
static const FName Player
플레이어 액터를 식별하기 위한 태그입니다.
Definition Onepiece.h:45