KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
ConveyorButton.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 "ConveyorButton.h"
5
6#include "ALingoGameState.h"
7#include "ConveyorBelt.h"
8#include "GameLogging.h"
10#include "UInteractWidget.h"
11#include "Components/BoxComponent.h"
12#include "Components/WidgetComponent.h"
13#include "Kismet/GameplayStatics.h"
14#include "Net/UnrealNetwork.h"
15
16#define INTERACT_WIDGET_PATH TEXT("/Game/CustomContents/UI/Widgets/WBP_InteractWidget.WBP_InteractWidget_C")
17
18// Sets default values
20{
21 // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
22 PrimaryActorTick.bCanEverTick = true;
23
24 RootSceneComp = CreateDefaultSubobject<USceneComponent>("RootSceneComp");
25 SetRootComponent(RootSceneComp);
26
27 ButtonMeshComp = CreateDefaultSubobject<USkeletalMeshComponent>("ButtonMeshComp");
28 ButtonMeshComp->SetupAttachment(GetRootComponent());
29 ConstructorHelpers::FObjectFinder<USkeletalMesh> buttonMeshRef(TEXT("/Script/Engine.SkeletalMesh'/Game/CustomContents/Platfrom/Assets/ConveyorBelt_Button/button.button'"));
30 if (buttonMeshRef.Succeeded())
31 {
32 ButtonMeshComp->SetSkeletalMesh(buttonMeshRef.Object);
33 ButtonMeshComp->SetRelativeScale3D(FVector(0.4f));
34 }
35
36 InteractableComp = CreateDefaultSubobject<UInteractableComponent>(TEXT("InteractableComp"));
37 InteractableComp->InteractionType = EInteractionType::Button;
38 InteractableComp->InteractionPrompt = TEXT("Activate");
39
40 WidgetComp = CreateDefaultSubobject<UWidgetComponent>(TEXT("WidgetComp"));
41 ConstructorHelpers::FClassFinder<UInteractWidget> WidgetRef(INTERACT_WIDGET_PATH);
42 if (WidgetRef.Succeeded())
43 {
44 WidgetComp->SetWidgetClass(WidgetRef.Class);
45 WidgetComp->SetupAttachment(GetRootComponent());
46 WidgetComp->SetWidgetSpace(EWidgetSpace::Screen);
47 WidgetComp->SetDrawSize(FVector2D(2048.0f, 1024.0f));
48 }
49
50 BoxComp = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxComp"));
51 BoxComp->SetupAttachment(GetRootComponent());
52 BoxComp->SetRelativeLocation(FVector(0.0f, 0.0f, 45.f));
53 BoxComp->SetBoxExtent(FVector(32, 32, 45));
54 BoxComp->SetCollisionEnabled(ECollisionEnabled::Type::QueryOnly);
55 BoxComp->SetCollisionObjectType(ECC_WorldStatic);
56 BoxComp->SetCollisionResponseToAllChannels(ECR_Block);
57
58 bReplicates = true;
59}
60
61// Called when the game starts or when spawned
63{
64 Super::BeginPlay();
65
66 // Find Conveyor Belt Actors
67 UGameplayStatics::GetAllActorsOfClass(GetWorld(), AConveyorBelt::StaticClass(), ConveyorBeltActors);
68
69 // Bind Delegate
70 InteractableComp->InitWidget(WidgetComp);
71 InteractableComp->OnInteractionTriggered.AddDynamic(this, &AConveyorButton::OnInteractionTriggered);
72 InteractableComp->OnOutlineStateChanged.AddDynamic(this, &AConveyorButton::OnOutlineStateChanged);
73
74 ALingoGameState* GameState = Cast<ALingoGameState>(GetWorld()->GetGameState());
75 GameState->OnReadResultUpdated.AddDynamic(this, &AConveyorButton::InitConveyorButton);
76}
77
78void AConveyorButton::GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const
79{
80 Super::GetLifetimeReplicatedProps(OutLifetimeProps);
81
82 DOREPLIFETIME(AConveyorButton, ConveyorBeltActors);
83 DOREPLIFETIME(AConveyorButton, bIsButtonOn);
84}
85
86// Called every frame
87void AConveyorButton::Tick(float DeltaTime)
88{
89 Super::Tick(DeltaTime);
90}
91
93{
94 if (bIsButtonOn)
95 {
96 bIsButtonOn = false;
97 for (const auto& Belt : ConveyorBeltActors)
98 {
99 AConveyorBelt* ConveyorBeltActor = Cast<AConveyorBelt>(Belt);
100 ConveyorBeltActor->InitConveyorBelt();
101 }
102 }
103}
104
106{
107 return bIsButtonOn;
108}
109
111{
112 if (ConveyorBeltActors.IsEmpty()) return;
113
115 // PRINT_STRING(TEXT("%d"), bIsButtonOn);
116 for (const auto& Belt : ConveyorBeltActors)
117 {
118 AConveyorBelt* ConveyorBeltActor = Cast<AConveyorBelt>(Belt);
119 ConveyorBeltActor->ChangeConveyorMovement();
120 }
121}
122
123void AConveyorButton::OnOutlineStateChanged(bool bShouldShowOutline)
124{
125 if (ButtonMeshComp)
126 {
127 ButtonMeshComp->SetRenderCustomDepth(bShouldShowOutline);
128 }
129}
#define INTERACT_WIDGET_PATH
YiSan 전반에서 사용하는 공용 인터페이스를 선언합니다.
void InitConveyorBelt()
void ChangeConveyorMovement()
void OnOutlineStateChanged(bool bShouldShowOutline)
TObjectPtr< class USkeletalMeshComponent > ButtonMeshComp
TObjectPtr< class USceneComponent > RootSceneComp
TObjectPtr< class UWidgetComponent > WidgetComp
virtual void GetLifetimeReplicatedProps(TArray< class FLifetimeProperty > &OutLifetimeProps) const override
TObjectPtr< class UBoxComponent > BoxComp
TObjectPtr< class UInteractableComponent > InteractableComp
virtual void Tick(float DeltaTime) override
virtual void BeginPlay() override
TArray< class AActor * > ConveyorBeltActors
void InitConveyorButton(const FResponseReadResult &result)
void OnInteractionTriggered(AActor *Interactor)
FOnReadResultUpdated OnReadResultUpdated