using UnityEngine; using System.Collections; using System.Runtime.InteropServices; using Module.Log; public class LoadWindFile { //链接指定系统函数 打开文件对话框 [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)] public static extern bool GetOpenFileName([In, Out] OpenFileName ofn); public static bool GetOFN([In, Out] OpenFileName ofn) { return GetOpenFileName(ofn); } //链接指定系统函数 另存为对话框 [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)] public static extern bool GetSaveFileName([In, Out] OpenFileName ofn); public static bool GetSFN([In, Out] OpenFileName ofn) { return GetSaveFileName(ofn); } public delegate void GetImagePathCallBack(string path); public static void LoadImage(GetImagePathCallBack getImgPath) { 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; openFileName.initialDir = Application.streamingAssetsPath.Replace('/', '\\');//默认路径 openFileName.title = "窗口标题"; openFileName.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008; if (GetSaveFileName(openFileName)) { if (getImgPath != null) { getImgPath(openFileName.file); } LogModule.DebugLog(openFileName.file); LogModule.DebugLog(openFileName.fileTitle); } } }