赞
踩
在Unity中使用弹窗选择路径
1,将System.Windows.Forms.dll放到Assets/Plugins文件夹下
2,代码中using System.Windows.Forms;
3,使用:
(1)选择文件夹
string defaultPath = "";
void Start () {
defaultPath = UnityEngine.Application.dataPath + "/GameAssets/";
}
private void SelectFolder()
{
DirectoryInfo mydir = new DirectoryInfo(defaultPath);
if(!mydir.Exists)
{
MessageBox.Show("请先创建资源文件夹");
return;
}
try
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = "选择要打包的资源文件夹";
fbd.ShowNewFolderButton = false;
fbd.RootFolder = Environment.SpecialFolder.MyComputer;//设置默认打开路径
fbd.SelectedPath = defaultPath; //默认打开路径下的详细路径
if (fbd.ShowDialog() == DialogResult.OK)
{
defaultPath = fbd.SelectedPath;
selectDir.text = fbd.SelectedPath;
}
}
catch(Exception e)
{
Debug.LogError("打开错误:"+e.Message);
return;
}
}
(2)选择文件
private void SelectFile()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = “file://” + UnityEngine.Application.dataPath;//默认打开路径
if (ofd.ShowDialog() == DialogResult.OK)
{
Debug.Log(ofd.FileName);
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。