From 58a4b3e04350e7a47fcc6fad9ec7eef80b3dcbf8 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Mon, 21 Aug 2023 20:21:03 +0800 Subject: [PATCH] =?UTF-8?q?YooAsset=E5=A2=9E=E5=8A=A0=E8=A1=A5=E4=B8=81?= =?UTF-8?q?=E5=8C=85=E5=AF=BC=E5=85=A5=E5=B7=A5=E5=85=B7=E5=92=8C=E8=A1=A5?= =?UTF-8?q?=E4=B8=81=E5=8C=85=E5=AF=B9=E6=AF=94=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit YooAsset增加补丁包导入工具和补丁包对比工具 --- .../Resource/YooAsset/PackageCompareWindow.cs | 138 ++++++++++++++++++ .../YooAsset/PackageCompareWindow.cs.meta | 11 ++ .../Resource/YooAsset/PackageImportWindow.cs | 89 +++++++++++ .../YooAsset/PackageImportWindow.cs.meta | 11 ++ 4 files changed, 249 insertions(+) create mode 100644 Assets/TEngine/Editor/Resource/YooAsset/PackageCompareWindow.cs create mode 100644 Assets/TEngine/Editor/Resource/YooAsset/PackageCompareWindow.cs.meta create mode 100644 Assets/TEngine/Editor/Resource/YooAsset/PackageImportWindow.cs create mode 100644 Assets/TEngine/Editor/Resource/YooAsset/PackageImportWindow.cs.meta diff --git a/Assets/TEngine/Editor/Resource/YooAsset/PackageCompareWindow.cs b/Assets/TEngine/Editor/Resource/YooAsset/PackageCompareWindow.cs new file mode 100644 index 00000000..2cea177f --- /dev/null +++ b/Assets/TEngine/Editor/Resource/YooAsset/PackageCompareWindow.cs @@ -0,0 +1,138 @@ +using System.IO; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEditor; + +namespace YooAsset.Editor +{ + public class PackageCompareWindow : EditorWindow + { + static PackageCompareWindow _thisInstance; + + [MenuItem("YooAsset/补丁包比对工具", false, 302)] + static void ShowWindow() + { + if (_thisInstance == null) + { + _thisInstance = EditorWindow.GetWindow(typeof(PackageCompareWindow), false, "补丁包比对工具", true) as PackageCompareWindow; + _thisInstance.minSize = new Vector2(800, 600); + } + _thisInstance.Show(); + } + + private string _manifestPath1 = string.Empty; + private string _manifestPath2 = string.Empty; + private readonly List _changeList = new List(); + private readonly List _newList = new List(); + private Vector2 _scrollPos1; + private Vector2 _scrollPos2; + + private void OnGUI() + { + GUILayout.Space(10); + EditorGUILayout.BeginHorizontal(); + if (GUILayout.Button("选择补丁包1", GUILayout.MaxWidth(150))) + { + string resultPath = EditorUtility.OpenFilePanel("Find", "Assets/", "bytes"); + if (string.IsNullOrEmpty(resultPath)) + return; + _manifestPath1 = resultPath; + } + EditorGUILayout.LabelField(_manifestPath1); + EditorGUILayout.EndHorizontal(); + + GUILayout.Space(10); + EditorGUILayout.BeginHorizontal(); + if (GUILayout.Button("选择补丁包2", GUILayout.MaxWidth(150))) + { + string resultPath = EditorUtility.OpenFilePanel("Find", "Assets/", "bytes"); + if (string.IsNullOrEmpty(resultPath)) + return; + _manifestPath2 = resultPath; + } + EditorGUILayout.LabelField(_manifestPath2); + EditorGUILayout.EndHorizontal(); + + if (string.IsNullOrEmpty(_manifestPath1) == false && string.IsNullOrEmpty(_manifestPath2) == false) + { + if (GUILayout.Button("比对差异", GUILayout.MaxWidth(150))) + { + ComparePackage(_changeList, _newList); + } + } + + EditorGUILayout.Space(); + using (new EditorGUI.DisabledScope(false)) + { + int totalCount = _changeList.Count; + EditorGUILayout.Foldout(true, $"差异列表 ( {totalCount} )"); + + EditorGUI.indentLevel = 1; + _scrollPos1 = EditorGUILayout.BeginScrollView(_scrollPos1); + { + foreach (var bundle in _changeList) + { + EditorGUILayout.LabelField($"{bundle.BundleName} | {(bundle.FileSize / 1024)}K"); + } + } + EditorGUILayout.EndScrollView(); + EditorGUI.indentLevel = 0; + } + + EditorGUILayout.Space(); + using (new EditorGUI.DisabledScope(false)) + { + int totalCount = _newList.Count; + EditorGUILayout.Foldout(true, $"新增列表 ( {totalCount} )"); + + EditorGUI.indentLevel = 1; + _scrollPos2 = EditorGUILayout.BeginScrollView(_scrollPos2); + { + foreach (var bundle in _newList) + { + EditorGUILayout.LabelField($"{bundle.BundleName}"); + } + } + EditorGUILayout.EndScrollView(); + EditorGUI.indentLevel = 0; + } + } + + private void ComparePackage(List changeList, List newList) + { + changeList.Clear(); + newList.Clear(); + + // 加载补丁清单1 + byte[] bytesData1 = FileUtility.ReadAllBytes(_manifestPath1); + PackageManifest manifest1 = ManifestTools.DeserializeFromBinary(bytesData1); + + // 加载补丁清单1 + byte[] bytesData2 = FileUtility.ReadAllBytes(_manifestPath2); + PackageManifest manifest2 = ManifestTools.DeserializeFromBinary(bytesData2); + + // 拷贝文件列表 + foreach (var bundle2 in manifest2.BundleList) + { + if (manifest1.TryGetPackageBundle(bundle2.BundleName, out PackageBundle bundle1)) + { + if (bundle2.FileHash != bundle1.FileHash) + { + changeList.Add(bundle2); + } + } + else + { + newList.Add(bundle2); + } + } + + // 按字母重新排序 + changeList.Sort((x, y) => string.Compare(x.BundleName, y.BundleName)); + newList.Sort((x, y) => string.Compare(x.BundleName, y.BundleName)); + + Debug.Log("资源包差异比对完成!"); + } + } +} diff --git a/Assets/TEngine/Editor/Resource/YooAsset/PackageCompareWindow.cs.meta b/Assets/TEngine/Editor/Resource/YooAsset/PackageCompareWindow.cs.meta new file mode 100644 index 00000000..219e1b44 --- /dev/null +++ b/Assets/TEngine/Editor/Resource/YooAsset/PackageCompareWindow.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 46962b0d15f63264bb45fe5be11f48cb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Editor/Resource/YooAsset/PackageImportWindow.cs b/Assets/TEngine/Editor/Resource/YooAsset/PackageImportWindow.cs new file mode 100644 index 00000000..67ea0918 --- /dev/null +++ b/Assets/TEngine/Editor/Resource/YooAsset/PackageImportWindow.cs @@ -0,0 +1,89 @@ +using System.IO; +using UnityEngine; +using UnityEditor; + +namespace YooAsset.Editor +{ + public class PackageImportWindow : EditorWindow + { + static PackageImportWindow _thisInstance; + + [MenuItem("YooAsset/补丁包导入工具", false, 301)] + static void ShowWindow() + { + if (_thisInstance == null) + { + _thisInstance = EditorWindow.GetWindow(typeof(PackageImportWindow), false, "补丁包导入工具", true) as PackageImportWindow; + _thisInstance.minSize = new Vector2(800, 600); + } + _thisInstance.Show(); + } + + private string _manifestPath = string.Empty; + + private void OnGUI() + { + GUILayout.Space(10); + EditorGUILayout.BeginHorizontal(); + if (GUILayout.Button("选择补丁包", GUILayout.MaxWidth(150))) + { + string resultPath = EditorUtility.OpenFilePanel("Find", "Assets/", "bytes"); + if (string.IsNullOrEmpty(resultPath)) + return; + _manifestPath = resultPath; + } + EditorGUILayout.LabelField(_manifestPath); + EditorGUILayout.EndHorizontal(); + + if (string.IsNullOrEmpty(_manifestPath) == false) + { + if (GUILayout.Button("导入补丁包(全部文件)", GUILayout.MaxWidth(150))) + { + AssetBundleBuilderHelper.ClearStreamingAssetsFolder(); + CopyPackageFiles(_manifestPath); + } + } + } + + private void CopyPackageFiles(string manifestFilePath) + { + string manifestFileName = Path.GetFileNameWithoutExtension(manifestFilePath); + string outputDirectory = Path.GetDirectoryName(manifestFilePath); + + // 加载补丁清单 + byte[] bytesData = FileUtility.ReadAllBytes(manifestFilePath); + PackageManifest manifest = ManifestTools.DeserializeFromBinary(bytesData); + + // 拷贝核心文件 + { + string sourcePath = $"{outputDirectory}/{manifestFileName}.bytes"; + string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{manifestFileName}.bytes"; + EditorTools.CopyFile(sourcePath, destPath, true); + } + { + string sourcePath = $"{outputDirectory}/{manifestFileName}.hash"; + string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{manifestFileName}.hash"; + EditorTools.CopyFile(sourcePath, destPath, true); + } + { + string fileName = YooAssetSettingsData.GetPackageVersionFileName(manifest.PackageName); + string sourcePath = $"{outputDirectory}/{fileName}"; + string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{fileName}"; + EditorTools.CopyFile(sourcePath, destPath, true); + } + + // 拷贝文件列表 + int fileCount = 0; + foreach (var packageBundle in manifest.BundleList) + { + fileCount++; + string sourcePath = $"{outputDirectory}/{packageBundle.FileName}"; + string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{packageBundle.FileName}"; + EditorTools.CopyFile(sourcePath, destPath, true); + } + + Debug.Log($"补丁包拷贝完成,一共拷贝了{fileCount}个资源文件"); + AssetDatabase.Refresh(); + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Editor/Resource/YooAsset/PackageImportWindow.cs.meta b/Assets/TEngine/Editor/Resource/YooAsset/PackageImportWindow.cs.meta new file mode 100644 index 00000000..49d1b511 --- /dev/null +++ b/Assets/TEngine/Editor/Resource/YooAsset/PackageImportWindow.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9054ed6f15278064aa817961e48878d5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: