์์
Person : Name(์ด๋ฆ), Year(์ฐ์ฐจ)
- Student : Id(ํ๋ฒ)
- Teacher : Id(์ฌ๋ฒ)
Person์๋ DoLesson์ด๋ผ๋ ๊ฐ์ ํจ์๊ฐ ์์
- Student์ DoLesson์ ์์ ์ ๋ฃ๋ ํ๋
- Teacher์ DoLesson์ ์์ ์ ๊ฐ๋ฅด์น๋ ํ๋
Object
ํญ์ ~.generated.h ํค๋๊ฐ ๋ง์ง๋ง์ ์์นํด์ผ ํ๋ค.
์๋ ํค๋๊ฐ ๋ง์ง๋ง
GameInstance
์๋ ํค๋๊ฐ ํญ์ ์์ ์์น
GameInstance
// 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 OBJECTREFLECTION_API UMyGameInstance : public UGameInstance
{
GENERATED_BODY()
public:
UMyGameInstance();
virtual void Init() override;
private:
UPROPERTY();
FString SchoolName;
};
UStudent* Student = NewObject<UStudent>(); // C++์ new์ ๋์ผ
UTeacher* Teacher = NewObject<UTeacher>();
// get์ผ๋ก ์ด๋ฆ ๊ฐ์ ธ์ค๊ธฐ
Student->SetName(TEXT("ํ์1"));
UE_LOG(LogTemp, Log, TEXT("์๋ก์ด ํ์ ์ด๋ฆ : %s"), *Student->GetName());
// reference๋ก ์ด๋ฆ ๊ฐ์ ธ์ค๊ธฐ
FString CurrentTeacherName;
FString NewTeacherName(TEXT("์ด๋์ฐ"));
FProperty* NameProp = UTeacher::StaticClass()->FindPropertyByName(TEXT("Name"));
if (NameProp) {
NameProp->GetValue_InContainer(Teacher, &CurrentTeacherName);
UE_LOG(LogTemp, Log, TEXT("ํ์ฌ ์ ์๋ ์ด๋ฆ : % s"), *Teacher->GetName());
// ์ด๋ฆ ๋ฐ๊พธ๊ธฐ
NameProp->SetValue_InContainer(Teacher, &NewTeacherName);
UE_LOG(LogTemp, Log, TEXT("์๋ก์ด ์ ์๋ ์ด๋ฆ : % s"), *Teacher->GetName());
}
UE_LOG(LogTemp, Log, TEXT("==========================="));
Student->DoLesson();
UFunction* DoLessonFunc = Teacher->GetClass()->FindFunctionByName(TEXT("DoLesson"));
if (DoLessonFunc) {
Teacher->ProcessEvent(DoLessonFunc, nullptr);
}
UE_LOG(LogTemp, Log, TEXT("==========================="));
Person
// 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 OBJECTREFLECTION_API UPerson : public UObject
{
GENERATED_BODY()
public:
UPerson(); // ์์ฑ์ ์ฝ๋
UFUNCTION()
virtual void DoLesson();
const FString& GetName() const; // get
void SetName(const FString& InName); // set
protected:
UPROPERTY() // ๋ฆฌํ๋ ์
์์คํ
์ ๋ฑ๋ก
FString Name;
UPROPERTY() // ๋ฆฌํ๋ ์
์์คํ
์ ๋ฑ๋ก
int32 Year;
private:
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "Person.h"
UPerson::UPerson()
{
Name = TEXT("ํ๊ธธ๋");
Year = 1;
}
void UPerson::DoLesson()
{
UE_LOG(LogTemp, Log, TEXT("%s๋์ด ์์
์ ์ฐธ์ฌํฉ๋๋ค."), *Name);
}
const FString& UPerson::GetName() const
{
return Name;
}
void UPerson::SetName(const FString& InName)
{
Name = InName;
}
Student
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "Person.h"
#include "Student.generated.h"
/**
*
*/
UCLASS()
class OBJECTREFLECTION_API UStudent : public UPerson
{
GENERATED_BODY()
public:
UStudent(); // ์์ฑ์
virtual void DoLesson() override;
private:
UPROPERTY()
int32 Id;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "Student.h"
UStudent::UStudent()
{
Name = TEXT("์ดํ์");
Year = 1;
Id = 1;
}
void UStudent::DoLesson()
{
Super::DoLesson();
UE_LOG(LogTemp, Log, TEXT("%dํ๋
%d๋ฒ %s๋์ด ์์
์ ๋ฃ์ต๋๋ค."), Year, Id, *Name);
}
Teacher
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "Person.h"
#include "Teacher.generated.h"
/**
*
*/
UCLASS()
class OBJECTREFLECTION_API UTeacher : public UPerson
{
GENERATED_BODY()
public:
UTeacher();
virtual void DoLesson() override;
private:
UPROPERTY()
int32 Id;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "Teacher.h"
UTeacher::UTeacher()
{
Name = TEXT("์ด์ ์");
Year = 3;
Id = 1;
}
void UTeacher::DoLesson()
{
Super::DoLesson();
UE_LOG(LogTemp, Log, TEXT("%d๋
์ฐจ ์ ์๋ %s๋์ด ์์
์ ๊ฐ์ํฉ๋๋ค."), Year, *Name);
}
'โ๏ธ ์์ง > ๐ซ ์ธ๋ฆฌ์ผ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Unreal] ํต์ ๋ฉ๊ฐ์ค์บ (1) | 2024.05.01 |
---|---|
[Unreal] ์์ํด์ ์ธ๋ฆฌ์ผ2022 ์ ๋ฆฌ (1) | 2024.05.01 |
[Unreal] ์ธ๋ฆฌ์ผ ์ค๋ธ์ ํธ ๋ฆฌํ๋ ์ ์์คํ (ensure, check) (0) | 2024.03.31 |
[Unreal] ์ธ๋ฆฌ์ผ ์ค๋ธ์ ํธ (0) | 2024.03.29 |
[Unreal] ์ธ๋ฆฌ์ผ C++ ๊ธฐ๋ณธ ํ์ ๊ณผ ๋ฌธ์์ด ์ฒ๋ฆฌ (0) | 2024.03.28 |