As shown in the figure, write such a function in the Unity Editor editor environment: click the "Browse" button to open a window, select a folder and record the path of the folder:
API used: OpenFolderPanel method in EditorUtility class:
// 摘要:
// Displays the "open folder" dialog and returns the selected path name.
// 参数:
// title:
//
// folder:
//
// defaultName:
[FreeFunction("RunOpenFolderPanel")]
public static string OpenFolderPanel(string title, string folder, string defaultName);
The first parameter title: indicates the title of the opened window:
The second parameter folder: the default path when opening the window, for example, if Application.dataPath is passed in, the path when opening is the Assets path of the project project:
The third parameter defaultName: When opening the window, the default content after "folder:":
Test code:
using UnityEngine;
using UnityEditor;
public class Example : EditorWindow
{
[MenuItem("SKFramework/Example")]
private static void Open()
{
GetWindow<Example>().Show();
}
private string path;
private void OnGUI()
{
//水平布局
GUILayout.BeginHorizontal();
{
GUILayout.Label("路径", GUILayout.Width(50f));
path = GUILayout.TextField(path);
if (GUILayout.Button("浏览", GUILayout.Width(50f)))
{
path = EditorUtility.OpenFolderPanel("窗口标题", Application.dataPath, "123");
}
}
GUILayout.EndHorizontal();
}
}
Welcome to the public account "Contemporary Wild Programmer"