From 43c5c7fb53d27826a087911c034c4eb47a17d121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Wed, 23 Jul 2025 15:41:00 +0800 Subject: [PATCH] =?UTF-8?q?feat=20:=20=E5=A2=9E=E5=8A=A0=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E5=89=8D=E7=BD=AE=E5=A4=84=E7=90=86=E6=89=A9=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 内置清单构建 --- .../Editor/PreprocessBuild.meta | 8 ++++ .../PreprocessBuild/PreprocessBuildCatalog.cs | 48 +++++++++++++++++++ .../PreprocessBuildCatalog.cs.meta | 11 +++++ 3 files changed, 67 insertions(+) create mode 100644 Assets/YooAsset/Samples~/Extension Sample/Editor/PreprocessBuild.meta create mode 100644 Assets/YooAsset/Samples~/Extension Sample/Editor/PreprocessBuild/PreprocessBuildCatalog.cs create mode 100644 Assets/YooAsset/Samples~/Extension Sample/Editor/PreprocessBuild/PreprocessBuildCatalog.cs.meta diff --git a/Assets/YooAsset/Samples~/Extension Sample/Editor/PreprocessBuild.meta b/Assets/YooAsset/Samples~/Extension Sample/Editor/PreprocessBuild.meta new file mode 100644 index 00000000..750d2d07 --- /dev/null +++ b/Assets/YooAsset/Samples~/Extension Sample/Editor/PreprocessBuild.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 36626e333f5e25c4581bc91db0189714 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Extension Sample/Editor/PreprocessBuild/PreprocessBuildCatalog.cs b/Assets/YooAsset/Samples~/Extension Sample/Editor/PreprocessBuild/PreprocessBuildCatalog.cs new file mode 100644 index 00000000..339fc58d --- /dev/null +++ b/Assets/YooAsset/Samples~/Extension Sample/Editor/PreprocessBuild/PreprocessBuildCatalog.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using System.IO; +using UnityEngine; + +namespace YooAsset +{ + public class PreprocessBuildCatalog : UnityEditor.Build.IPreprocessBuildWithReport + { + public int callbackOrder { get { return 0; } } + + /// + /// 在构建应用程序前自动生成内置资源目录文件。 + /// 原理:搜索StreamingAssets目录下的所有资源文件,将这些文件信息写入文件,然后在运行时做查询用途。 + /// + public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report) + { + YooLogger.Log("Begin to create catalog file !"); + + string rootPath = YooAssetSettingsData.GetYooDefaultBuildinRoot(); + DirectoryInfo rootDirectory = new DirectoryInfo(rootPath); + if (rootDirectory.Exists == false) + { + Debug.LogWarning($"Can not found StreamingAssets root directory : {rootPath}"); + return; + } + + // 搜索所有Package目录 + DirectoryInfo[] subDirectories = rootDirectory.GetDirectories(); + foreach (var subDirectory in subDirectories) + { + string packageName = subDirectory.Name; + string pacakgeDirectory = subDirectory.FullName; + try + { + bool result = CatalogTools.CreateCatalogFile(null, packageName, pacakgeDirectory); //TODO 自行处理解密 + 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/PreprocessBuild/PreprocessBuildCatalog.cs.meta b/Assets/YooAsset/Samples~/Extension Sample/Editor/PreprocessBuild/PreprocessBuildCatalog.cs.meta new file mode 100644 index 00000000..5400d792 --- /dev/null +++ b/Assets/YooAsset/Samples~/Extension Sample/Editor/PreprocessBuild/PreprocessBuildCatalog.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6b5abe115ebfe1344b674db78b2edf6c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: