UE4调用Windows文件操作面板
(1)PickDirectory(拾取目录)
FString AbsoluteGameContentDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir());
FString Directory;
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
if (DesktopPlatform)
{
TSharedPtr<SWindow> ParentWindow = FSlateApplication::Get().FindWidgetWindow(BrowseButton.ToSharedRef());
void* ParentWindowHandle = (ParentWindow.IsValid() && ParentWindow->GetNativeWindow().IsValid()) ? ParentWindow->GetNativeWindow()->GetOSWindowHandle() : nullptr;
FString StartDirectory = FEditorDirectories::Get().GetLastDirectory(ELastDirectory::GENERIC_IMPORT);
if (bRelativeToGameContentDir && !IsValidPath(StartDirectory, bRelativeToGameContentDir))
{
StartDirectory = AbsoluteGameContentDir;
}
// Loop until; a) the user cancels (OpenDirectoryDialog returns false), or, b) the chosen path is valid (IsValidPath returns true)
for (;;)
{
if (DesktopPlatform->OpenDirectoryDialog(ParentWindowHandle, LOCTEXT("FolderDialogTitle", "Choose a directory").ToString(), StartDirectory, Directory))
{
FText FailureReason;
if (IsValidPath(Directory, bRelativeToGameContentDir, &FailureReason))
{
FEditorDirectories::Get().SetLastDirectory(ELastDirectory::GENERIC_IMPORT, Directory);
if (bRelativeToGameContentDir)
{
Directory = Directory.RightChop(AbsoluteGameContentDir.Len());
}
else if (bUseRelativePath)
{
Directory = IFileManager::Get().ConvertToRelativePath(*Directory);
}
}
else
{
StartDirectory = Directory;
FMessageDialog::Open(EAppMsgType::Ok, FailureReason);
continue;
}
}
break;
}
}
在DirectoryPathStructCustomization.cpp的OnPickDirectory函数
(2)拾取文件目录
具体参考LandscapeEditorDetailCustomization_TargetLayers.cpp的OnImportLayer函数
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
DesktopPlatform->OpenFileDialog(
FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr),
(3)保存文件
具体参考LandscapeEditorDetailCustomization_TargetLayers.cpp的OnExportLayer函数
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
esktopPlatform->SaveFileDialog()
GEditor
GEditor包含了很多对编辑器操作。
(1)在编辑器获取编辑器所在世界的指针
UWorld* EditorWorld = GEditor->GetEditorWorldContext().World();
利用这个编辑器世界的指针就是可以在编辑器里进行各种操作,如SpawnActor,GetActorsOfClass等等
(2)其它的如选中某个Actor,设置选中一个Actor相应的颜色,材质等等接口都在GEditor。