public static string historyPath = ""; //记忆的路径 /// <summary> /// 加载外部图片 /// </summary> /// <param name="directoryName">填写GameConfigs里面的静态路径(例如pingmianPath)</param> public static void LoadSingleTexture(System.Action <Sprite, byte[]> callback) { OpenFileName openfilename = new OpenFileName(); openfilename.structSize = Marshal.SizeOf(openfilename); openfilename.filter = "图片文件(*.jpg*.png)\0*.jpg;*.png"; openfilename.file = new string(new char[256]); openfilename.maxFile = openfilename.file.Length; openfilename.fileTitle = new string(new char[64]); openfilename.maxFileTitle = openfilename.fileTitle.Length; string path = Application.streamingAssetsPath; path = path.Replace('/', '\\'); //默认路径 openfilename.initialDir = path; if (isLoadAllTextureFirst) { openfilename.initialDir = Application.streamingAssetsPath.Replace('/', '\\');//外部文件打开的路径 } else { openfilename.initialDir = historyPath.Replace('/', '\\'); } //添加路径记忆 //ofn.initialDir = "D:\\MyProject\\UnityOpenCV\\Assets\\StreamingAssets"; openfilename.title = "Open Project"; openfilename.defExt = "JPG"; //显示文件的类型 //注意 一下项目不一定要全选 但是0x00000008项不要缺少 openfilename.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008; if (DllOpenFileDialog.GetSaveFileName(openfilename)) { //确定了图片的选择 Game.Instance.StartCoroutine(LoadSingleImage(openfilename.file, callback)); string[] newPath = openfilename.file.Split('\\'); for (int i = 0; i < newPath.Length - 1; i++) { historyPath += (newPath[i] + "\\"); } isLoadAllTextureFirst = false; } else { //点击的取消按键 } }
static public string GetFilePathByDialog(string title, string defaultPath) { OpenDialogFile openFileName = new OpenDialogFile(); openFileName.structSize = Marshal.SizeOf(openFileName); //openFileName.filter = "Excel文件(*.xlsx)\0*.xlsx"; openFileName.file = new string(new char[512]); openFileName.maxFile = openFileName.file.Length; openFileName.fileTitle = new string(new char[64]); openFileName.maxFileTitle = openFileName.fileTitle.Length; openFileName.initialDir = defaultPath; openFileName.title = title; openFileName.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008; DllOpenFileDialog.GetSaveFileName(openFileName); return(openFileName.file); }