From aab2c4625ef731f74bbabdd944cfc64348b4e810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Thu, 13 Nov 2025 15:54:08 +0800 Subject: [PATCH] feat #671 --- .../DefaultBuildinFileSystem/CatalogTools.cs | 28 +++++++++ .../CreateEmptyCatalogWindow.cs | 62 +++++++++++++++++++ .../CreateEmptyCatalogWindow.cs.meta | 11 ++++ .../PackageComparatorWindow.cs | 2 +- .../PackageImporter/PackageImporterWindow.cs | 2 +- 5 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateEmptyCatalogWindow.cs create mode 100644 Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateEmptyCatalogWindow.cs.meta diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/CatalogTools.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/CatalogTools.cs index 81b122f6..03b9f791 100644 --- a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/CatalogTools.cs +++ b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/CatalogTools.cs @@ -118,6 +118,34 @@ namespace YooAsset Debug.Log($"Succeed to save catalog file : {binaryFilePath}"); return true; } + + /// + /// 生成空的包裹内置自由目录文件 + /// + public static bool CreateEmptyCatalogFile(string packageName, string packageVersion, string outputPath) + { + // 创建内置清单实例 + var buildinFileCatalog = new DefaultBuildinFileCatalog(); + buildinFileCatalog.FileVersion = CatalogDefine.FileVersion; + buildinFileCatalog.PackageName = packageName; + buildinFileCatalog.PackageVersion = packageVersion; + + // 创建输出文件 + string jsonFilePath = $"{outputPath}/{DefaultBuildinFileSystemDefine.BuildinCatalogJsonFileName}"; + if (File.Exists(jsonFilePath)) + File.Delete(jsonFilePath); + SerializeToJson(jsonFilePath, buildinFileCatalog); + + // 创建输出文件 + string binaryFilePath = $"{outputPath}/{DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName}"; + if (File.Exists(binaryFilePath)) + File.Delete(binaryFilePath); + SerializeToBinary(binaryFilePath, buildinFileCatalog); + + UnityEditor.AssetDatabase.Refresh(); + Debug.Log($"Succeed to save catalog file : {binaryFilePath}"); + return true; + } #endif /// diff --git a/Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateEmptyCatalogWindow.cs b/Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateEmptyCatalogWindow.cs new file mode 100644 index 00000000..ea244849 --- /dev/null +++ b/Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateEmptyCatalogWindow.cs @@ -0,0 +1,62 @@ +using System.IO; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEditor; + +namespace YooAsset.Editor +{ + public class CreateEmptyCatalogWindow : EditorWindow + { + static CreateEmptyCatalogWindow _thisInstance; + + [MenuItem("Tools/空清单生成工具(Catalog)", false, 102)] + static void ShowWindow() + { + if (_thisInstance == null) + { + _thisInstance = EditorWindow.GetWindow(typeof(CreateEmptyCatalogWindow), false, "空清单生成工具", true) as CreateEmptyCatalogWindow; + _thisInstance.minSize = new Vector2(800, 600); + } + _thisInstance.Show(); + } + + private string _packageName = string.Empty; + + private void OnGUI() + { + GUILayout.Space(10); + EditorGUILayout.BeginHorizontal(); + _packageName = EditorGUILayout.TextField("Package Name", _packageName); + EditorGUILayout.EndHorizontal(); + + if (string.IsNullOrEmpty(_packageName) == false) + { + if (GUILayout.Button("生成空的Catalog文件", GUILayout.MaxWidth(150))) + { + string outputPath = EditorTools.OpenFolderPanel("输出目录", "Assets/"); + if (string.IsNullOrEmpty(outputPath) == false) + { + CreateEmptyCatalogFile(outputPath); + } + } + } + } + + private void CreateEmptyCatalogFile(string outputPath) + { + try + { + bool result = CatalogTools.CreateEmptyCatalogFile(_packageName, string.Empty, outputPath); + if (result == false) + { + Debug.LogError($"Create package {_packageName} catalog file failed ! See the detail error in console !"); + } + } + catch (System.Exception ex) + { + Debug.LogError($"Create package {_packageName} catalog file failed ! {ex.Message}"); + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateEmptyCatalogWindow.cs.meta b/Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateEmptyCatalogWindow.cs.meta new file mode 100644 index 00000000..35e5b8dd --- /dev/null +++ b/Assets/YooAsset/Samples~/Extension Sample/Editor/CreateBuildinCatalog/CreateEmptyCatalogWindow.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 211aadfc630b2ec419d5efce05e8aabe +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Extension Sample/Editor/PackageComparator/PackageComparatorWindow.cs b/Assets/YooAsset/Samples~/Extension Sample/Editor/PackageComparator/PackageComparatorWindow.cs index 3bc616f3..6af12fa5 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Editor/PackageComparator/PackageComparatorWindow.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Editor/PackageComparator/PackageComparatorWindow.cs @@ -10,7 +10,7 @@ namespace YooAsset.Editor { static PackageComparatorWindow _thisInstance; - [MenuItem("Tools/补丁包比对工具", false, 102)] + [MenuItem("Tools/补丁包比对工具", false, 103)] static void ShowWindow() { if (_thisInstance == null) diff --git a/Assets/YooAsset/Samples~/Extension Sample/Editor/PackageImporter/PackageImporterWindow.cs b/Assets/YooAsset/Samples~/Extension Sample/Editor/PackageImporter/PackageImporterWindow.cs index 7d89dc08..ac3ac2e6 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Editor/PackageImporter/PackageImporterWindow.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Editor/PackageImporter/PackageImporterWindow.cs @@ -8,7 +8,7 @@ namespace YooAsset.Editor { static PackageImporterWindow _thisInstance; - [MenuItem("Tools/补丁包导入工具", false, 101)] + [MenuItem("Tools/补丁包导入工具", false, 104)] static void ShowWindow() { if (_thisInstance == null)