Java教程

UE4 Editor Plugin UI

本文主要是介绍UE4 Editor Plugin UI,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

UE4 Editor Plugin UI

keyvalue
ModuleDesktopPlatform
Header/Engine/Source/Developer/DesktopPlatform/Public/IDesktopPlatform.h
Include#include "IDesktopPlatform.h"

Choose Local Folder to save

选择本地硬盘目录:

#include "IDesktopPlatform.h

IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
//默认路径
FString DefaultLocation(FEditorDirectories::Get().GetLastDirectory(ELastDirectory::GENERIC_IMPORT));
FString Path = DefaultLocation;
bool bOpened = false;
if (DesktopPlatform)
{
	bOpened = DesktopPlatform->OpenDirectoryDialog(
		FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr),
		TEXT("Choose folder to save"),
		DefaultLocation,
		Path
	);
	if (bOpened)
		Path += "/";
}

Choose Content Folder

选择 UE4 project content 目录:

1

static FString Path = "/Game/";
TSharedRef<SDlgPickPath> PickContentPathDlg =
					SNew(SDlgPickPath)
					.Title(LOCTEXT("ChooseImportRootContentPath", "Choose Location for importing the H3D content"))
					.DefaultPath(FText::FromString(Path));

if (PickContentPathDlg->ShowModal() == EAppReturnType::Cancel)
{
	return;
}

Path = PickContentPathDlg->GetPath().ToString() + "/";

Open & Save File Dialog

打开本地文件和保存为本地文件对话框。

#include "IDesktopPlatform.h"
namespace FileDialogHelpers
{
	/**
	 * @param Title                  The title of the dialog
	 * @param FileTypes              Filter for which file types are accepted and should be shown
	 * @param InOutLastPath          Keep track of the last location from which the user attempted an import
	 * @param DefaultFile            Default file name to use for saving.
	 * @param OutOpenFilenames       The list of filenames that the user attempted to open
	 *
	 * @return true if the dialog opened successfully and the user accepted; false otherwise.
	 */
	bool SaveFile(const FString& Title, const FString& FileTypes, FString& InOutLastPath, const FString& DefaultFile, FString& OutFilename)
	{
		OutFilename = FString();

		IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
		bool bFileChosen = false;
		TArray<FString> OutFilenames;
		if (DesktopPlatform)
		{
			bFileChosen = DesktopPlatform->SaveFileDialog(
				FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr),
				Title,
				InOutLastPath,
				DefaultFile,
				FileTypes,
				EFileDialogFlags::None,
				OutFilenames
			);
		}

		bFileChosen = (OutFilenames.Num() > 0);

		if (bFileChosen)
		{
			// User successfully chose a file; remember the path for the next time the dialog opens.
			InOutLastPath = OutFilenames[0];
			OutFilename = OutFilenames[0];
		}

		return bFileChosen;
	}

	/**
	 * @param Title                  The title of the dialog
	 * @param FileTypes              Filter for which file types are accepted and should be shown
	 * @param InOutLastPath			 Keep track of the last location from which the user attempted an import
	 * @param DialogMode             Multiple items vs single item.
	 * @param OutOpenFilenames       The list of filenames that the user attempted to open
	 *
	 * @return true if the dialog opened successfully and the user accepted; false otherwise.
	 */
	bool OpenFiles(const FString& Title, const FString& FileTypes, FString& InOutLastPath, EFileDialogFlags::Type DialogMode, TArray<FString>& OutOpenFilenames)
	{
		IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
		bool bOpened = false;
		if (DesktopPlatform)
		{
			bOpened = DesktopPlatform->OpenFileDialog(
				FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr),
				Title,
				InOutLastPath,
				TEXT(""),
				FileTypes,
				DialogMode,
				OutOpenFilenames
			);
		}

		bOpened = (OutOpenFilenames.Num() > 0);

		if (bOpened)
		{
			// User successfully chose a file; remember the path for the next time the dialog opens.
			InOutLastPath = OutOpenFilenames[0];
		}

		return bOpened;
	}
}

Message Dialog

2

#include "Misc/MessageDialog.h"

#define LOCTEXT_NAMESPACE "FH3DEditorModule"

FText DialogText = LOCTEXT("PluginDialogText", "Next please choose folder to save......");
FText DialogTitle = LOCTEXT("PluginDialogTitle", "Choose save folder");

FMessageDialog::Open(EAppMsgType::Ok, DialogText,&DialogTitle);

参考

  1. UE4 Editor Plugin UI
这篇关于UE4 Editor Plugin UI的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!