Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 지우개신공 #pc자기진단 #ram미인식 #컴퓨터고장해결 #램인식불량 #pc자가수리 #컴퓨터고장해결 #조립pc
- 으
- nixos한글키보드
- streamlit
- nixos한글설정\
- 미니프로젝트
- ossca
- inxos
- 파이썬서버
- VUE
- 프메
- 오픈소스
- Express
- 스트림릿
- R
- Jinja2
- JWT
- 블랙스크린복구
- Enhanced Input System
- flask
- 메모리인식불량
- 디자드
- EnhancedInput
- pandas
- 마인크래프트뮤지컬
- 언리얼뮤지컬
- 판다스
- 알고풀자
- 정글사관학교
- Bootstrap4
Archives
- Today
- Total
Today, I will
[Unreal] singleton UGameInstance와 interface의 활용 예시 본문
1. 게임인스턴스
.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "SGameInstance.generated.h"
/**
*
*/
UCLASS()
class TRACESOFTHEFOX_API USGameInstance : public UGameInstance
{
GENERATED_BODY()
public:
USGameInstance();
virtual void Init() override;
virtual void Shutdown() override;
};
.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Game/SGameInstance.h"
#include "Kismet/KismetSystemLibrary.h"
USGameInstance::USGameInstance()
{
}
void USGameInstance::Init()
{
Super::Init();
UE_LOG(LogTemp, Log, TEXT("USGameInstance Init"));
UKismetSystemLibrary::PrintString(this, TEXT("USGameInstance this Init"));
// this 대신 GetWorld 가능
UKismetSystemLibrary::PrintString(GetWorld(), TEXT("USGameInstance GetWorld Init"));
}
void USGameInstance::Shutdown()
{
Super::Shutdown();
UE_LOG(LogTemp, Log, TEXT("USGameInstance Shutdown"));
UKismetSystemLibrary::PrintString(this, TEXT("USGameInstance this Shutdown"));
// this 대신 GetWorld 가능
UKismetSystemLibrary::PrintString(GetWorld(), TEXT("USGameInstance GetWorld Shutdown")); // 월드 객체를 가져올 수 있는 액터들 같은 경우 가능
}
2. 인터페이스
끼워넣을 수 있는 ‘행동’
생성해서 만들면 Uclass 와 Iclass가 있다.
.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "SFlyable.generated.h"
// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class USFlyable : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class TRACESOFTHEFOX_API ISFlyable
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
virtual void Fly() = 0;
// 이렇게 '순수 가상 함수'가 들어있는 클래스를 인터페이스라고 한다.
};
새로 object 클래스를 일단 상속받은 c++ 클래스를 만든다.
.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "SFlyable.h" // 상속하기 위해 가져옴
#include "SPigeon.generated.h"
/**
*
*/
UCLASS()
class TRACESOFTHEFOX_API USPigeon : public UObject, public ISFlyable // 인터페이스 상속
{
GENERATED_BODY()
public:
USPigeon(); // 생성자
virtual void Fly() override;
private:
UPROPERTY()
FString Name;
};
피죤 cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Examples/SPigeon.h"
USPigeon::USPigeon()
{
Name = TEXT("Pigeon");
}
void USPigeon::Fly()
{
UE_LOG(LogTemp, Log, TEXT("%s is now Flying"), *Name)
}
싱글톤에 추가해본다.
// Fill out your copyright notice in the Description page of Project Settings.
#include "Game/SGameInstance.h"
#include "Kismet/KismetSystemLibrary.h"
#include "Examples/SFlyable.h"
#include "Examples/SPigeon.h"
USGameInstance::USGameInstance()
{
}
void USGameInstance::Init()
{
Super::Init();
UE_LOG(LogTemp, Log, TEXT("USGameInstance Init"));
UKismetSystemLibrary::PrintString(this, TEXT("USGameInstance this Init"));
// this 대신 GetWorld
UKismetSystemLibrary::PrintString(GetWorld(), TEXT("USGameInstance GetWorld Init"));
USPigeon* pigeon1 = NewObject<USPigeon>();
ISFlyable* Bird1 = Cast<ISFlyable>(pigeon1);
//현업에서 인터페이스 개념은 대부분 이런 식으로 업캐스팅 하기 위함
if (nullptr != Bird1) {
Bird1->Fly();
}
}
void USGameInstance::Shutdown()
{
Super::Shutdown();
UE_LOG(LogTemp, Log, TEXT("USGameInstance Shutdown"));
UKismetSystemLibrary::PrintString(this, TEXT("USGameInstance this Shutdown"));
// this 대신 GetWorld
UKismetSystemLibrary::PrintString(GetWorld(), TEXT("USGameInstance GetWorld Shutdown")); // 월드 객체를 가져올 수 있는 액터들 같은 경우 가능
}
'Unreal' 카테고리의 다른 글
[Unreal] 언리얼 Json 직렬화 및 역직렬화 (0) | 2023.11.23 |
---|---|
[Unreal] 언리얼 직렬화, Serialize (1) | 2023.11.23 |
[Unreal] Maximo fbx 애니메이팅과 무기 socket 적용을 위한 animNotifyState (0) | 2023.11.07 |
[Unreal] 언리얼 VFX 에디터 나이아가라(Niagara) (0) | 2023.11.07 |
[Unreal] 언리얼 멀티플레이어 세팅(1) (0) | 2023.11.01 |