Unreal Engine 4 프로그래밍 c++/기능
Unreal c++ Interface uint + n 사용시 주의점.
코닥쿠
2022. 6. 24. 00:48
반응형
언리얼에 블루프린트로 인자값을 받을수 있지만 c++에서 Implementation으로 이용하여 생성을 할때 블루프린트에서는 uint8, uint16 .... 값이 없기때문에 이점에서는 유의해야한다.
그래서 uint값을 받기 위해서는 오직 c++에서만 이용해야한다.
Interface.h
class SOULNETWORKPROJECT_API IMenuInterface
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
UFUNCTION()
virtual void Join(uint32 Index) = 0; //상속의 방식으로 선언해줌
};
virtualclass.h
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "Blueprint/UserWidget.h"
#include "Public/Interface/MenuInterface.h" //Interface 헤더포함//
#include "SoulNetworkProjectGameInstance.generated.h"
UCLASS()
class SOULNETWORKPROJECT_API ProjectGameInstance : public UGameInstance, public IMenuInterface
{
GENERATED_BODY()
public:
UProjectGameInstance(const FObjectInitializer& ObjectInitializer);
virtual void Init();
//-------------------Interface Functions--------------------------//
UFUNCTION()
virtual void Join(uint32 Index) override; //이런식으로 재정의를 해줌//
////////////////////////////////////////////////////////////////////
};
virtualclass.cpp
//이런식으로 uint + n 값이 정상적으로 인식된다.//
void UProjectGameInstance::Join(uint32 Index)
{
if(!SessionInterface || !SessionSearch) return;
if(MainMenuWidget) MainMenuWidget->Teardown();
SessionInterface->JoinSession(0, SESSION_NAME,SessionSearch->SearchResults[Index]);
}
InterfaceCallingFunction
void UMainMenu::JoinServer()
{
//클래스인자값을 받아 InterfaceClass가 상속받았는지 유무를 파악하여 함수를 호출하는방법//
if (SelectedIndex.IsSet() && GetGameInstance()->GetClass()->ImplementsInterface(UMenuInterface::StaticClass()))
{
UE_LOG(LogTemp,Warning, TEXT("Selected index %d"), SelectedIndex.GetValue());
Cast<IMenuInterface>(GetGameInstance())->Join(SelectedIndex.GetValue());
}
//이런식으로 InterfaceClass 캐스팅하여 직접생성으로 함수를 호출하는방법//
IMenuInterface* Interface = Cast<IMenuInterface>(GetGameInstance())
if(SelectedIndex.IsSet() && Interface)
{
UE_LOG(LogTemp,Warning, TEXT("Selected index %d"), SelectedIndex.GetValue());
Interface->Join(SelectedIndex.GetValue());
}
}
위에 있는 호출방식은 c++에서만 호출이 가능함.
반응형