[UE_5] 모듈 제작 -3 (메세지 출력(Notify,Dialog))
만약에 특정 기능에서 잘못된 입력이라던가 잘못된 결과가 나올시에 언리얼에서는 메세지 다이얼로그가 뜨는데, 이걸 띄우는걸 해보자.
https://docs.unrealengine.com/4.27/en-US/API/Runtime/Core/Misc/FMessageDialog/
FMessageDialog
[FMessageDialog](API\Runtime\Core\Misc\FMessageDialog) These functions open a message dialog and display the specified informations these.
docs.unrealengine.com
언리얼 문서는 이걸 통해서 확인이 가능하다.
if (NumOfDuplicates <= 0)
{
FText MsgTitle = FText::FromString(TEXT("Warning"));
FMessageDialog::Open(EAppMsgType::Ok, FText::FromString(TEXT("Please enter a Valid Number")),&MsgTitle);
Print(TEXT("Please enter a Valid number"), FColor::Red);
return;
}
Open 이라는 기능을 통해서
EAppReturnType::Type FMessageDialog::Open( EAppMsgType::Type MessageType, const FText& Message, const FText* OptTitle )
EAppMsgType을 설정하고 (Ok, Yes or No) 텍스트를 저장하는데 FText 데이터형이다. FromString이라는 기능이 있어서 TEXT()를 통해서 string을 FText로 변환할 수 있다.
마지막 매개변수는 언리얼 메세지의 제목이라고 생각하면 된다.
Open 기능을 살펴보면 EAppReturnType이라는 데이터형으로 저장되어 있다.
그래서 나중에 DebugHelper 같이 편리하게 코드 만들어줄 헤더에 추가할려고 할때,
EAppReturnType::Type ShowMsgDialog(EAppMsgType::Type MsgType, const FString& Msg, bool bShowMsgAsWarning = true)
{
if (bShowMsgAsWarning)
{
FText MsgTitle = FText::FromString(TEXT("Warning"));
return FMessageDialog::Open(MsgType, FText::FromString(Msg), &MsgTitle);
}
else
{
return FMessageDialog::Open(MsgType, FText::FromString(Msg));
}
}
이런식으로 추가해주면 편하다.
https://docs.unrealengine.com/4.27/en-US/API/Runtime/Slate/Widgets/Notifications/SNotificationList/
SNotificationList
A list of non-intrusive messages about the status of currently active work.
docs.unrealengine.com
FSlateNotificationManager
A class which manages a group of notification windows
docs.unrealengine.com
이 둘을 보면 에디터에서 오른쪽 아래에 보면 나오는 알림창 같은걸 사용할 수 있다.
void ShowNotifyInfo(const FString& Msg)
{
// 들어온 메세지 NotificationInfo에 저장
FNotificationInfo NotifyInfo(FText::FromString(Msg));
// 설정
NotifyInfo.bUseLargeFont = true;
NotifyInfo.FadeOutDuration = 5.f;
// SlateNotifucationManager에서 추가하기
FSlateNotificationManager::Get().AddNotification(NotifyInfo);
}
이런식으로 디버그헬퍼에 추가해주면 쉽게 사용이 가능하다.
Manager를 통해 알림에 넣어주면 알아서 알림창이 뜨게 된다.
이렇게 되면 툴을 통한 메세지 출력이 전부 다 가능하다.
완료 되었을땐 노티파이가, 틀렸을땐 Warning 다이얼로그가 나오게된 셈이다.