在Unity中使用彈窗選擇路徑
1,將System.Windows.Forms.dll放到Assets/Plugins文件夾下(dll文件位置:\Unity\Editor\Data\Mono\lib\mono\2.0)
2,代碼中using System.Windows.Forms;
3,使用:
(1)選擇文件夾
private void SelectFolder()
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
filePath = fbd.SelectedPath;
}
}
(2)選擇文件
private void SelectFile()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = “file://” + UnityEngine.Application.dataPath;//默認打開路徑
if (ofd.ShowDialog() == DialogResult.OK)
{
Debug.Log(ofd.FileName);
}
}