KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
ListenAnswer.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 "ListenAnswer.h"
5
6#include "CityNameWidget.h"
7#include "FListenData.h"
9#include "UGameDataManager.h"
10#include "UHookComponent.h"
11#include "Components/WidgetComponent.h"
12#include "Net/UnrealNetwork.h"
13
14
15// Sets default values
17{
18 // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
19 PrimaryActorTick.bCanEverTick = true;
20
21 Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
22 SetRootComponent(Mesh);
23
24 NameWidgetComp = CreateDefaultSubobject<UWidgetComponent>(TEXT("NameWidget"));
25 NameWidgetComp->SetupAttachment(GetRootComponent());
26
27 InteractableComp = CreateDefaultSubobject<UInteractableComponent>(TEXT("Interactable"));
28 InteractableComp->InteractionType = EInteractionType::PickUp;
29 InteractableComp->InteractionPrompt = TEXT("Pick Up");
30
31 // Initial settings (Physics 설정은 BeginPlay에서 수행)
32 Mesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
33 Mesh->SetCollisionProfileName(TEXT("PhysicsActor"));
34
35 HookComp = CreateDefaultSubobject<UHookComponent>(TEXT("Hook"));
36
37 // 물리 복제 설정
38 Mesh->SetIsReplicated(true);
39
40 // Replication
41 bReplicates = true;
42 SetNetUpdateFrequency(100.0f); // 높은 업데이트 빈도로 부드러운 네트워크 동기화
43 SetMinNetUpdateFrequency(33.0f); // 최소 30fps 업데이트 보장
44}
45
46// Called when the game starts or when spawned
48{
49 Super::BeginPlay();
50
51 // Physics 설정 (생성자에서 이동)
52 if (Mesh)
53 {
54 Mesh->SetSimulatePhysics(true);
55 Mesh->SetEnableGravity(true);
56 Mesh->SetMassOverrideInKg(NAME_None, 50.f, true);
57 }
58
59 NameWidgetComp->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform);
60 NameWidgetComp->SetRelativeLocation(FVector(0, 0, 10));
61
62 // 델리게이트 바인딩
64 {
65 InteractableComp->OnOutlineStateChanged.AddDynamic(this, &AListenAnswer::OnOutlineStateChanged);
66 }
67}
68
69void AListenAnswer::GetLifetimeReplicatedProps(TArray<class FLifetimeProperty>& OutLifetimeProps) const
70{
71 Super::GetLifetimeReplicatedProps(OutLifetimeProps);
72
73 DOREPLIFETIME(AListenAnswer, AnswerData);
74}
75
76// Called every frame
77void AListenAnswer::Tick(float DeltaTime)
78{
79 Super::Tick(DeltaTime);
80}
81
87
89{
90 // 게임 스레드가 아니면 게임 스레드로 dispatch
91 if (!IsInGameThread())
92 {
93 AsyncTask(ENamedThreads::GameThread, [this]()
94 {
95 UpdateMesh();
96 });
97 return;
98 }
99
100 if (!ListenDataTable)
101 {
102 UE_LOG(LogTemp, Error, TEXT("ListenDataTable is null!"));
103 return;
104 }
105
106 if (!ListenDataTable) return;
107
108 TArray<FListenData*> AllRows;
109 ListenDataTable->GetAllRows<FListenData>(TEXT("UpdateMesh"), AllRows);
110
111 for (FListenData* Row : AllRows)
112 {
113 if (Row && Row->Word == AnswerData.word1.name)
114 {
115 if (Row->FoodPath)
116 {
117 Mesh->SetStaticMesh(Row->FoodPath);
118 return;
119 }
120 }
121 }
122
123 // 일치하는 데이터를 찾지 못함
124 UE_LOG(LogTemp, Warning, TEXT("No matching ListenData found for: %s"), *AnswerData.word1.name);
125}
126
128{
129 // 게임 스레드가 아니면 게임 스레드로 dispatch
130 if (!IsInGameThread())
131 {
132 AsyncTask(ENamedThreads::GameThread, [this]()
133 {
135 });
136 return;
137 }
138
139 // Widget이 아직 초기화되지 않았을 수 있으므로 체크
140 if (!NameWidgetComp || !NameWidgetComp->GetWidget())
141 return;
142
143 UCityNameWidget* NameWidget = Cast<UCityNameWidget>(NameWidgetComp->GetWidget());
144 if (NameWidget)
145 {
146 NameWidget->SetCityName(AnswerData.word1.name);
147 }
148}
149
150void AListenAnswer::OnOutlineStateChanged(bool bShouldShowOutline)
151{
152 if (Mesh)
153 {
154 Mesh->SetRenderCustomDepth(bShouldShowOutline);
155 }
156}
157
FListenData 구조체를 선언합니다.
UGameDataManager 클래스를 선언합니다.
Hook 대상 표시 컴포넌트
void OnOutlineStateChanged(bool bShouldShowOutline)
class UStaticMeshComponent * Mesh
TObjectPtr< class UHookComponent > HookComp
class UDataTable * ListenDataTable
class UWidgetComponent * NameWidgetComp
void UpdateNameWidget()
virtual void BeginPlay() override
FListenAnswerData AnswerData
void OnRep_AnswerData()
virtual void Tick(float DeltaTime) override
virtual void GetLifetimeReplicatedProps(TArray< class FLifetimeProperty > &OutLifetimeProps) const override
TObjectPtr< class UInteractableComponent > InteractableComp
void SetCityName(FString InCityName)
FWordInfo word1
시나리오 단어 정보
듣기 학습 데이터를 정의하는 구조체
Definition FListenData.h:19
FString name