๐ฉ ์ธํฐํ์ด์ค
๊ฐ์ฒด๊ฐ ๋ฐ๋์ ๊ตฌํํด์ผ ํ ํ๋์ ์ง์ ํ๋๋ฐ ํ์ฉ๋๋ ํ์
๋คํ์ฑ์ ๊ตฌํ, ์์กด์ฑ์ด ๋ถ๋ฆฌ๋ ์ค๊ณ์ ์ ์ฉํ๊ฒ ํ์ฉ
๐ ํน์ง
1. ์ธํฐํ์ด์ค๋ฅผ ์์ฑํ๋ฉด ๋ ๊ฐ์ ํด๋์ค๊ฐ ์์ฑ๋จ
- U๋ก ์์ํ๋ ํ์ ํด๋์ค : ํด๋์ค ํ์ ์ ๋ณด ์ ๊ณต
- I๋ก ์์ํ๋ ์ธํฐํ์ด์ค ํด๋์ค : ์ค์ง์ ์ธ ์ค๊ณ ๋ฐ ๊ตฌํ
2. ๊ฐ์ฒด๋ฅผ ์ค๊ณํ ๋ I ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉ
- U ํ์ ํด๋์ค ์ ๋ณด๋ ๋ฐํ์์์ ์ธํฐํ์ด์ค ๊ตฌํ ์ฌ๋ถ๋ฅผ ํ์ ํ๋ ์ฉ๋๋ก ์ฌ์ฉ๋จ
- ์ค์ ๋ก U ํ์ ํด๋์ค์์ ์์ ํ ์ผ์ ์์
- ์ธํฐํ์ด์ค์ ๊ด๋ จ๋ ๊ตฌ์ฑ ๋ฐ ๊ตฌํ์ I ์ธํฐํ์ด์ค ํด๋์ค์์ ์งํ
3. C++ ์ธํฐํ์ด์ค์ ํน์ง
- ์ถ์ ํ์ ์ผ๋ก๋ง ์ ์ธํ ์ ์๋ Java, C#๊ณผ ๋ฌ๋ฆฌ ์ธ๋ฆฌ์ผ์ ์ธํฐํ์ด์ค์๋ ๊ตฌํ์ด ๊ฐ๋ฅํจ
๐ ์ธ๋ฆฌ์ผ ์์ง์์ ๊ฒ์ ์ปจํ ์ธ ๋ฅผ ๊ตฌ์ฑํ๋ ์ค๋ธ์ ํธ์ ์ค๊ณ ์์
์๋์ ๋ฐฐ์น๋๋ ๋ชจ๋ ์ค๋ธ์ ํธ, ์ ์์ง์ด๋ ์ค๋ธ์ ํธ๋ฅผ ํฌํจ(actor)
์์ง์ด๋ ์ค๋ธ์ ํธ(pawn) : ๊ธธ์ฐพ๊ธฐ ์์คํ ์ ๋ฐ๋์ ์ฌ์ฉํ๋ฉด์ ์์ง์ด๋ ์ค๋ธ์ ํธ
๐ง ์์ : ์์ ์ ์ฐธ์ฌํ๋ ์ฌ๋๊ณผ ์ฐธ์ฌํ์ง ์๋ ์ฌ๋์ ๊ตฌ๋ถ
- ์์ ์ ๋ฐ๋์ ์ฐธ์ฌํด์ผ ํ๋ ํ๊ต ๊ตฌ์ฑ์ : ํ์, ์ ์
- ์์ ์ ์ฐธ์ฌํ์ง ์๋ ํ๊ต ๊ตฌ์ฑ์ : ๊ต์ง์
- ์์ ํ๋์ ๊ด๋ จ๋ ์ธํฐํ์ด์ค : ILessonInterface
๋ค๋ฅธ ํ๋ก์ ํธ์ ์๋ ์คํฌ๋ฆฝํธ ๋ณต์ฌํด์ ๋ถ์ด๊ธฐ(์๋์ฐ ์ฐฝ ๋ด์์) ๐ ๋ถ์ธ ํ์ refresh ์ฒ๋ฆฌํด์ผ ์ ๋๋ก ๋ค์ด์ด
๋ณต์ฌํด์จ ์ฝ๋๋ฅผ ๋ฐ๋ก ์ฌ์ฉํ์ง ๋ชปํ๋ค.
ํด๋น ์ฝ๋์ ํค๋์์ class๋ช ์ ํ์ฌ ํด๋์ค ํค๋๋ก ๋ฐ๊ฟ์ฃผ์ด์ผ ํ๋ค.
๐ ์ธ๋ฆฌ์ผ ์ธํฐํ์ด์ค
์์ฑ๋ ์ธํฐํ์ด์ค ํค๋
์ฒดํฌ ๋ถ๋ถ์ ์ธํฐํ์ด์ค ๊ธฐ๋ฅ๋ค์ ๋ฃ์ ์ ์๋ค.
โจ ์ธํฐํ์ด์ค ํค๋(cpp๋ ์์ ํ์ง ์์)
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "LessonInterface.generated.h"
// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class ULessonInterface : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class UNREALINTERFACE_API ILessonInterface
{
GENERATED_BODY()
public:
// virtual void DoLesson() = 0;
// ์๋์ ๊ฐ์ด ๋น์ด๋์ง ์๊ณ ์ธ ์๋ ์๋ค.
// ์ด ๊ฒฝ์ฐ ๋์ด์ ์ถ์ ํด๋์ค๊ฐ ์๋๊ธฐ ๋๋ฌธ์ ํ์ ํด๋์ค์์ ๊ฐ์ ๋ก ๊ตฌํํ์ง ์์๋ ๋๋ค.
virtual void DoLesson()
{
UE_LOG(LogTemp, Log, TEXT("์์
์ ์
์ฅํฉ๋๋ค."));
}
};
โจ Person(h & cpp)
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "Person.generated.h"
/**
*
*/
UCLASS()
class UNREALINTERFACE_API UPerson : public UObject
{
GENERATED_BODY()
public:
UPerson();
FORCEINLINE FString& GetName() { return Name; }
FORCEINLINE void SetName(const FString& InName) { Name = InName; }
protected:
UPROPERTY()
FString Name;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "Person.h"
UPerson::UPerson()
{
Name = TEXT("ํ๊ธธ๋");
}
โจ Student (h & cpp)
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Person.h"
#include "LessonInterface.h"
#include "Student.generated.h"
/**
*
*/
UCLASS()
class UNREALINTERFACE_API UStudent : public UPerson, public ILessonInterface
{
GENERATED_BODY()
public:
UStudent();
virtual void DoLesson() override;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "Student.h"
UStudent::UStudent()
{
Name = TEXT("์ดํ์");
}
void UStudent::DoLesson()
{
// ์์๋ฐ๋ ๊ฒ์ด Person์ด๊ธฐ ๋๋ฌธ์ Super ํค์๋๋ฅผ ์ฌ์ฉํ์ง ๋ชปํ๋ค.
ILessonInterface::DoLesson();
UE_LOG(LogTemp, Log, TEXT("%s๋์ ๊ณต๋ถํฉ๋๋ค."), *Name);
}
โจ MyGameInstance(h & cpp)
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "MyGameInstance.generated.h"
/**
*
*/
UCLASS()
class UNREALINTERFACE_API UMyGameInstance : public UGameInstance
{
GENERATED_BODY()
public:
UMyGameInstance();
virtual void Init() override;
private:
UPROPERTY();
FString SchoolName;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyGameInstance.h"
#include "Student.h"
#include "Teacher.h"
#include "Staff.h"
UMyGameInstance::UMyGameInstance() // ์์ฑ์ ์ฝ๋
{
SchoolName = TEXT("๊ธฐ๋ณธํ๊ต"); // CDO์ ๊ธฐ๋ณธ๊ฐ ์ค์
}
void UMyGameInstance::Init()
{
Super::Init();
UE_LOG(LogTemp, Log, TEXT("=========="));
TArray<UPerson*> Persons = { NewObject<UStudent>(), NewObject<UTeacher>(), NewObject<UStaff>()};
for (const auto Person : Persons) {
UE_LOG(LogTemp, Log, TEXT("๊ตฌ์ฑ์ ์ด๋ฆ : %s"), *Person->GetName());
}
UE_LOG(LogTemp, Log, TEXT("=========="));
// ํ๋ณํ : ์ธํฐํ์ด์ค๋ฅผ ์์๋ฐ์๋์ง ์ฌ๋ถ๋ฅผ ํ์ธํ ์ ์๋ค(์๋ ๊ฒฝ์ฐ null ๋ฐํ)
for (const auto Person : Persons) {
ILessonInterface* LessonInterface = Cast<ILessonInterface>(Person);
// ์ธํฐํ์ด์ค๊ฐ ๊ตฌํ๋์ด ์๋ ๊ฒฝ์ฐ
if (LessonInterface) {
UE_LOG(LogTemp, Log, TEXT("%s๋์ ์์
์ ์ฐธ์ฌํ ์ ์์ต๋๋ค."), *Person->GetName());
LessonInterface->DoLesson();
}
else {
UE_LOG(LogTemp, Log, TEXT("%s๋์ ์์
์ ์ฐธ์ฌํ ์ ์์ต๋๋ค."), *Person->GetName());
}
}
UE_LOG(LogTemp, Log, TEXT("=========="));
}
๐ง ์ธ๋ฆฌ์ผ C++ ์ธํฐํ์ด์ค
- ํด๋์ค๊ฐ ๋ฐ๋์ ๊ตฌํํด์ผ ํ๋ ๊ธฐ๋ฅ์ ์ง์ ํ๋๋ฐ ์ฌ์ฉ
- C++์ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ค์ค์์์ ์ง์ํ์ง๋ง, ์ธ๋ฆฌ์ผ C++์ ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํด ๊ฐ๊ธ์ ์ถ์๋ ๋ค์ค์์์ ํํ๋ก ๊ตฌํํ๋ ๊ฒ์ด ํฅํ ์ ์ง๋ณด์์ ๋์๋๋ค.
- ์ธ๋ฆฌ์ผ C++ ์ธํฐํ์ด์ค๋ ๋ ๊ฐ์ ํด๋์ค๋ฅผ ์์ฑํ๋ค.
- ์ธ๋ฆฌ์ผ C++ ์ธํฐํ์ด์ค๋ ์ถ์ ํ์ ์ผ๋ก ๊ฐ์ ๋์ง ์๊ณ , ๋ด๋ถ์ ๊ธฐ๋ณธ ํจ์๋ฅผ ๊ตฌํํ ์ ์๋ค.
- ์ธ๋ฆฌ์ผ C++ ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ๋ฉด, ํด๋์ค๊ฐ ์ํํด์ผ ํ ์๋ฌด๋ฅผ ๋ช ์์ ์ผ๋ก ์ง์ ํ ์ ์์ด ์ข์ ๊ฐ์ฒด ์ค๊ณ๋ฅผ ๋ง๋๋๋ฐ ๋์์ ์ค ์ ์๋ค.
'โ๏ธ ์์ง > ๐ซ ์ธ๋ฆฌ์ผ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Unreal] ๋ธ๋ฆฌ๊ฒ์ดํธ (0) | 2024.05.04 |
---|---|
[Unreal] ์ปดํฌ์ง์ (0) | 2024.05.03 |
[Unreal] ํต์ ๋ฉ๊ฐ์ค์บ (1) | 2024.05.01 |
[Unreal] ์์ํด์ ์ธ๋ฆฌ์ผ2022 ์ ๋ฆฌ (1) | 2024.05.01 |
[Unreal] ์ธ๋ฆฌ์ผ ์ค๋ธ์ ํธ ๋ฆฌํ๋ ์ ์์คํ 2 (0) | 2024.03.31 |