1、仅限编辑器可用
using UnityEngine;
using UnityEditor;
public class FolderSelector : MonoBehaviour
{
void Start()
{
// 调用OpenFolderPanel,其中参数分别是标题、默认路径、是否显示文件扩展名
string folderPath = EditorUtility.OpenFolderPanel("Select Folder", "", "");
if (folderPath.Length != 0)
{
Debug.Log("Selected Folder: " + folderPath);
}
}
}
2、发布可用(Windows)
using SFB;
string folderPath;
private string _path;
void OpenFileEvent()
{
/*EditorUtility.OpenFolderPanel("Select Folder", "", "");*/
folderPath = WriteResult(StandaloneFileBrowser.OpenFolderPanel("Select Folder", "", true));
if (folderPath.Length != 0)
{
fileName_txt.text = folderPath;
}
}
public string WriteResult(string[] paths)
{
if (paths.Length == 0)
{
return null;
}
_path = "";
for (int i = 0; i < paths.Length; i++)
{
_path += i < paths.Length - 1 ? (paths[i] + "\n") : paths[i];
}
return _path;
}

5130

被折叠的 条评论
为什么被折叠?



