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: