UE5 打开文件窗口

代码

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
32
33
34
35
36
37
38
39
40
41
42
#include "DesktopPlatformModule.h"

FString OpenDirectoryWindow(FString Title, FString DefaultPath)
{
FString outStr = TEXT("");

IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
if (DesktopPlatform)
{
bool bOpened = DesktopPlatform->OpenDirectoryDialog(
FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr),
Title,
DefaultPath,
outStr);
}
return outStr;
}

FString OpenFileWindow(FString Title, FString DefaultPath, FString DefaultFile, FString FileTypes)
{
TArray<FString> OpenedFiles;
FString outStr = TEXT("");

IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
if (DesktopPlatform)
{
bool bOpened = DesktopPlatform->OpenFileDialog(
FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr),
Title,
DefaultPath,
DefaultFile,
FileTypes, // TEXT("File|*.png;*raw;*r8"),
EFileDialogFlags::None,
OpenedFiles);

if (bOpened && OpenedFiles.Num() > 0)
{
outStr = *OpenedFiles.Last();
}
}
return outStr;
}

UE5 打开文件窗口
https://automask.github.io/wild/2022/11/21/lab/S_Unreal_OpenWindow/
作者
Kyle Zhou
发布于
2022年11月21日
许可协议