记录好每次打包的文件MD5和版本信息后,我们需要根据这些信息判断出哪些文件需要热更,从而打出热更补丁。在这里我们需要制作一个编辑器窗口,方便指定热更的目标平台和版本号。
热更包打包窗口
在ResFrame——Editor文件夹内新建WindowsFile
脚本,这是一个调用Windows系统文件管理器的脚本。
WindowsFile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| using System; using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential,CharSet = CharSet.Auto)] public class OpenFileName { public int structSize = 0; public IntPtr dlgOwner = IntPtr.Zero; public IntPtr instance = IntPtr.Zero; public String filter = null; public String customFilter = null; public int maxCustFilter = 0; public int filterIndex = 0; public String file = null; public int maxFile = 0; public String fileTitle = null; public int maxFileTitle = 0; public String initialDir = null; public String title = null; public int flags = 0; public short fileOffset = 0; public short fileExtension = 0; public String defExt = null; public IntPtr custData = IntPtr.Zero; public IntPtr hook = IntPtr.Zero; public String templateName = null; public IntPtr reservedPtr = IntPtr.Zero; public int reservedInt = 0; public int flagsEx = 0; } public class LocalDialog { [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); } }
|
在ResFrame——Editor——Resource文件夹内新建BundleHotFix
脚本。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| using UnityEngine; using UnityEditor; using System.Runtime.InteropServices;
public class BundleHotFix : EditorWindow { [MenuItem("Tools/打包热更包")] static void Init() { BundleHotFix window = EditorWindow.GetWindow<BundleHotFix>(false,"热更包界面",true); window.Show(); } string md5Path = ""; string hotCount = "1"; OpenFileName m_OpenFileName = null; private void OnGUI() { GUILayout.BeginHorizontal(); md5Path = EditorGUILayout.TextField("ABMD5路径", md5Path, GUILayout.Width(350), GUILayout.Height(20)); if (GUILayout.Button("选择版本ABMD5文件", GUILayout.Width(150), GUILayout.Height(30))) { m_OpenFileName = new OpenFileName(); m_OpenFileName.structSize = Marshal.SizeOf(m_OpenFileName); m_OpenFileName.filter = "ABMD5文件(*.bytes)\0*.bytes"; m_OpenFileName.file = new string(new char[256]); m_OpenFileName.maxFile = m_OpenFileName.file.Length; m_OpenFileName.fileTitle = new string(new char[64]); m_OpenFileName.maxFileTitle = m_OpenFileName.fileTitle.Length; m_OpenFileName.initialDir = (Application.dataPath + "/../Version").Replace("/", "\\"); m_OpenFileName.title = "选择MD5窗口"; m_OpenFileName.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000008; if (LocalDialog.GetSaveFileName(m_OpenFileName)) { Debug.Log(m_OpenFileName.file); md5Path = m_OpenFileName.file; } } GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(); hotCount = EditorGUILayout.TextField("热更补丁版本:", hotCount, GUILayout.Width(350), GUILayout.Height(20)); GUILayout.EndHorizontal();
if (GUILayout.Button("开始打热更包", GUILayout.Width(100), GUILayout.Height(50))) { if(!string.IsNullOrEmpty(md5Path) && md5Path.EndsWith(".bytes")) { BundleEditor.Build(true, md5Path, hotCount); } } } }
|