From 8451c96e705c2259db1554188a6a7533d81dbad9 Mon Sep 17 00:00:00 2001 From: gaoxin Date: Thu, 3 Jun 2021 21:32:44 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=B7=A5=E5=85=B7=E3=80=91=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=A4=9A=E9=80=89=E6=96=87=E4=BB=B6=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Editor/AutoPack.cs | 12 +++- Assets/Scripts/Editor/Util/ProcessUtil.cs | 72 +++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/Assets/Editor/AutoPack.cs b/Assets/Editor/AutoPack.cs index 3dd7fb3bfd..a174c0c7d1 100644 --- a/Assets/Editor/AutoPack.cs +++ b/Assets/Editor/AutoPack.cs @@ -86,8 +86,18 @@ public class AutoPack : EditorWindow Rect wr = new Rect(0, 0, 500, 700); var buildWin = GetWindowWithRect(wr, true); buildWin.titleContent = new GUIContent("打包工具"); - buildWin.Show(); + buildWin.Show(); } + //[MenuItem("自动化打包/一键导出2")] + //private static void EzBuildPack2() + //{ + // //创建窗口 + // string[] ss = ProcessUtil.OpenFileWin(); + // foreach(string s in ss) + // { + // Debug.Log(s); + // } + //} private void OnGUI() { diff --git a/Assets/Scripts/Editor/Util/ProcessUtil.cs b/Assets/Scripts/Editor/Util/ProcessUtil.cs index 6c055a16cc..a1367c781e 100644 --- a/Assets/Scripts/Editor/Util/ProcessUtil.cs +++ b/Assets/Scripts/Editor/Util/ProcessUtil.cs @@ -1,10 +1,50 @@ using UnityEngine; using UnityEditor; using System.IO; +using System; +using System.Runtime.InteropServices; namespace GameEditor.Util { + /*这是C#引用非托管的C/C++的DLL的一种定义定义结构体的方式,主要是为了内存中排序,LayoutKind有两个属性Sequential和Explicit + Sequential表示顺序存储,结构体内数据在内存中都是顺序存放的Explicit表示精确布局,需要用FieldOffset()设置每个成员的位置这都是 + 为了使用非托管的指针准备的,CharSet=CharSet.Ansi表示编码方式 + */ + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public struct OpenFileName + { + public int structSize; //结构的内存大小 + public IntPtr dlgOwner; //设置对话框的句柄 + public IntPtr instance; //根据flags标志的设置,确定instance是谁的句柄,不设置则忽略 + public string filter; //调取文件的过滤方式 + public string customFilter; //一个静态缓冲区 用来保存用户选择的筛选器模式 + public int maxCustFilter; //缓冲区的大小 + public int filterIndex; //指向的缓冲区包含定义过滤器的字符串对 + public string file; //存储调取文件路径 + public int maxFile; //存储调取文件路径的最大长度 至少256 + public string fileTitle; //调取的文件名带拓展名 + public int maxFileTitle; //调取文件名最大长度 + public string initialDir; //最初目录 + public string title; //打开窗口的名字 + public int flags; //初始化对话框的一组位标志 参数类型和作用查阅官方API + public short fileOffset; //文件名前的长度 + public short fileExtension; //拓展名前的长度 + public string defExt; //默认的拓展名 + public IntPtr custData; //传递给lpfnHook成员标识的钩子子程的应用程序定义的数据 + public IntPtr hook; //指向钩子的指针。除非Flags成员包含OFN_ENABLEHOOK标志,否则该成员将被忽略。 + public string templateName; //模块中由hInstance成员标识的对话框模板资源的名称 + public IntPtr reservedPtr; + public int reservedInt; + public int flagsEx; //可用于初始化对话框的一组位标志 + } + + public class WindowDll + { + [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)] + public static extern bool GetOpenFileName([In, Out] OpenFileName ofn); + } + public static class ProcessUtil { @@ -62,5 +102,37 @@ namespace GameEditor.Util System.Diagnostics.Process.Start("notepad.exe", tPath); //用记事本 } + public static string[] OpenFileWin() + { + //初始化 + OpenFileName ofn = new OpenFileName(); + ofn.structSize = Marshal.SizeOf(ofn); + ofn.filter = "All Files\0*.*\0\0"; + ofn.file = new string(new char[1024]); + ofn.maxFile = ofn.file.Length; + ofn.fileTitle = new string(new char[64]); + ofn.maxFileTitle = ofn.fileTitle.Length; + string path = Application.streamingAssetsPath; + path = path.Replace('/', '\\'); + ofn.initialDir = path; //默认路径 + ofn.title = "Open Project"; + ofn.defExt = "JPG";//显示文件的类型 + //注意 一下项目不一定要全选 但是0x00000008项不要缺少 + ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR + string[] strs = null; + //判断是否打开文件 + if (WindowDll.GetOpenFileName(ofn)) + { + //多选文件 + string[] Splitstr = { "\0" }; + strs = ofn.file.Split(Splitstr, StringSplitOptions.RemoveEmptyEntries); + } + else + { + Debug.LogFormat("路径为空"); + + } + return strs; + } } } \ No newline at end of file