打开对话框,获取所选文件路径
Unity:Unity2021.3.6f1c1
public static string[] OpenFilePanel
(string title,
string directory,
ExtensionFilter[] extensions,
bool multiselect)
using SFB;
using UnityEngine;
public class OpenDialog : MonoBehaviour
{
string pathInfo = string.Empty;
private void OnGUI()
{
if (GUILayout.Button("文件多选"))
{
ExtensionFilter[] extensions = new ExtensionFilter[2];
extensions[0] = new ExtensionFilter("All Files", "*");
extensions[1] = new ExtensionFilter("Image Files", "png", "jpg", "jpeg");
string[] paths = StandaloneFileBrowser.OpenFilePanel("文件标题",
Application.dataPath + "/..", extensions, true);
pathInfo = PathCombine(paths);
}
GUILayout.Label(pathInfo);
}
string PathCombine(string[] paths)
{
var length = paths.Length;
var info = string.Empty;
int i;
for (i = 0; i < length - 1; i++)
{
info += (paths[i] + "\n");
}
info += paths[i];
return info;
}
}