From 233e477bc80cf7d88110719c5e341fc526af2696 Mon Sep 17 00:00:00 2001 From: hevinci Date: Thu, 17 Mar 2022 21:52:08 +0800 Subject: [PATCH] Update AssetBundleBuilder --- .../AssetBundleBuilder/BuildBundleInfo.cs | 19 ++-- .../BuildReport/BuildReport.cs | 8 +- .../BuildReport/ReportAssetInfo.cs | 18 ++++ .../BuildReport/ReportBundleInfo.cs | 33 +++++++ .../BuildTasks/TaskBuilding.cs | 2 +- .../BuildTasks/TaskCreateReport.cs | 86 +++++++++++++++++-- .../BuildTasks/TaskGetBuildMap.cs | 9 +- 7 files changed, 150 insertions(+), 25 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs index c1cea38..1270897 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs @@ -14,9 +14,10 @@ namespace YooAsset.Editor public string BundleName { private set; get; } /// - /// 包含的资源列表 + /// 参与构建的资源列表 + /// 注意:不包含冗余资源或零依赖资源 /// - public readonly List Assets = new List(); + public readonly List BuildinAssets = new List(); /// /// 是否为原生文件 @@ -25,7 +26,7 @@ namespace YooAsset.Editor { get { - foreach (var asset in Assets) + foreach (var asset in BuildinAssets) { if (asset.IsRawAsset) return true; @@ -45,7 +46,7 @@ namespace YooAsset.Editor /// public bool IsContainsAsset(string assetPath) { - foreach (var assetInfo in Assets) + foreach (var assetInfo in BuildinAssets) { if (assetInfo.AssetPath == assetPath) { @@ -63,7 +64,7 @@ namespace YooAsset.Editor if (IsContainsAsset(assetInfo.AssetPath)) throw new System.Exception($"Asset is existed : {assetInfo.AssetPath}"); - Assets.Add(assetInfo); + BuildinAssets.Add(assetInfo); } /// @@ -82,8 +83,8 @@ namespace YooAsset.Editor /// public string[] GetAssetTags() { - List result = new List(Assets.Count); - foreach (var assetInfo in Assets) + List result = new List(BuildinAssets.Count); + foreach (var assetInfo in BuildinAssets) { foreach (var assetTag in assetInfo.AssetTags) { @@ -99,7 +100,7 @@ namespace YooAsset.Editor /// public string[] GetBuildinAssetPaths() { - return Assets.Select(t => t.AssetPath).ToArray(); + return BuildinAssets.Select(t => t.AssetPath).ToArray(); } /// @@ -107,7 +108,7 @@ namespace YooAsset.Editor /// public BuildAssetInfo[] GetCollectAssetInfos() { - return Assets.Where(t => t.IsCollectAsset).ToArray(); + return BuildinAssets.Where(t => t.IsCollectAsset).ToArray(); } /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs index 3d93a5c..bc33833 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs @@ -17,14 +17,14 @@ namespace YooAsset.Editor public BuildSummary Summary = new BuildSummary(); /// - /// 资源包列表 + /// 资源对象列表 /// - public List BundleInfos; + public List AssetInfos = new List(); /// - /// 冗余的资源列表 + /// 资源包列表 /// - public List RedundancyList; + public List BundleInfos = new List(); /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportAssetInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportAssetInfo.cs index 5b21fbf..9f5646f 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportAssetInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportAssetInfo.cs @@ -7,6 +7,24 @@ namespace YooAsset.Editor [Serializable] public class ReportAssetInfo { + /// + /// 资源路径 + /// + public string AssetPath; + /// + /// 所属资源包 + /// + public string MainBundle; + + /// + /// 依赖的资源包 + /// + public List DependBundles = new List(); + + /// + /// 依赖的资源列表 + /// + public List DependAssets = new List(); } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportBundleInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportBundleInfo.cs index 73afc48..06627c6 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportBundleInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportBundleInfo.cs @@ -7,6 +7,39 @@ namespace YooAsset.Editor [Serializable] public class ReportBundleInfo { + /// + /// 资源包完整名称 + /// + public string BundleName; + /// + /// 哈希值 + /// + public string Hash; + + /// + /// 文件校验码 + /// + public string CRC; + + /// + /// 文件大小(字节数) + /// + public long SizeBytes; + + /// + /// 文件版本 + /// + public int Version; + + /// + /// Tags + /// + public string[] Tags; + + /// + /// Flags + /// + public int Flags; } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs index 78c945a..9f1afcb 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs @@ -36,7 +36,7 @@ namespace YooAsset.Editor if (bundleInfo.IsRawFile) { string dest = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; - foreach(var buildAsset in bundleInfo.Assets) + foreach(var buildAsset in bundleInfo.BuildinAssets) { if(buildAsset.IsRawAsset) EditorTools.CopyFile(buildAsset.AssetPath, dest, true); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs index 791b231..21c6b8d 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs @@ -1,8 +1,6 @@ using System; -using System.IO; -using System.Text; -using System.Collections; using System.Collections.Generic; +using System.IO; namespace YooAsset.Editor { @@ -20,8 +18,10 @@ namespace YooAsset.Editor private void CreateReportFile(AssetBundleBuilder.BuildParametersContext buildParameters, TaskGetBuildMap.BuildMapContext buildMapContext) { + PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory); BuildReport buildReport = new BuildReport(); + // 概述信息 buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion; buildReport.Summary.BuildTime = DateTime.Now.ToString(); buildReport.Summary.BuildSeconds = 0; @@ -29,10 +29,8 @@ namespace YooAsset.Editor buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion; buildReport.Summary.ApplyRedundancy = buildParameters.Parameters.ApplyRedundancy; buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension; - buildReport.Summary.IsCollectAllShaders = AssetBundleCollectorSettingData.Setting.IsCollectAllShaders; buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName; - buildReport.Summary.IsForceRebuild = buildParameters.Parameters.IsForceRebuild; buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags; buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption; @@ -41,14 +39,88 @@ namespace YooAsset.Editor buildReport.Summary.IsIgnoreTypeTreeChanges = buildParameters.Parameters.IsIgnoreTypeTreeChanges; buildReport.Summary.IsDisableLoadAssetByFileName = buildParameters.Parameters.IsDisableLoadAssetByFileName; - //buildReport.BundleInfos = buildMapContext.BundleInfos; - buildReport.RedundancyList = buildMapContext.RedundancyList; + // 资源对象列表 + buildReport.AssetInfos = new List(patchManifest.AssetList.Count); + foreach (var patchAsset in patchManifest.AssetList) + { + var mainBundle = patchManifest.BundleList[patchAsset.BundleID]; + ReportAssetInfo reportAssetInfo = new ReportAssetInfo(); + reportAssetInfo.AssetPath = patchAsset.AssetPath; + reportAssetInfo.MainBundle = mainBundle.BundleName; + reportAssetInfo.DependBundles = GetDependBundles(patchManifest, patchAsset); + reportAssetInfo.DependAssets = GetDependAssets(buildMapContext, mainBundle.BundleName, patchAsset.AssetPath); + buildReport.AssetInfos.Add(reportAssetInfo); + } + + // 资源包列表 + buildReport.BundleInfos = new List(patchManifest.BundleList.Count); + foreach (var patchBundle in patchManifest.BundleList) + { + ReportBundleInfo reportBundleInfo = new ReportBundleInfo(); + reportBundleInfo.BundleName = patchBundle.BundleName; + reportBundleInfo.Hash = patchBundle.Hash; + reportBundleInfo.CRC = patchBundle.CRC; + reportBundleInfo.SizeBytes = patchBundle.SizeBytes; + reportBundleInfo.Version = patchBundle.Version; + reportBundleInfo.Tags = patchBundle.Tags; + reportBundleInfo.Flags = patchBundle.Flags; + buildReport.BundleInfos.Add(reportBundleInfo); + } // 删除旧文件 string filePath = $"{buildParameters.PipelineOutputDirectory}/{ResourceSettingData.Setting.ReportFileName}"; if (File.Exists(filePath)) File.Delete(filePath); + + // 序列化文件 BuildReport.Serialize(filePath, buildReport); } + + /// + /// 获取资源对象依赖的所有资源包 + /// + private List GetDependBundles(PatchManifest patchManifest, PatchAsset patchAsset) + { + List dependBundles = new List(patchAsset.DependIDs.Length); + foreach(int index in patchAsset.DependIDs) + { + string dependBundleName = patchManifest.BundleList[index].BundleName; + dependBundles.Add(dependBundleName); + } + return dependBundles; + } + + /// + /// 获取资源对象依赖的其它所有资源 + /// + private List GetDependAssets(TaskGetBuildMap.BuildMapContext buildMapContext, string bundleName, string assetPath) + { + List result = new List(); + if(buildMapContext.TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo)) + { + BuildAssetInfo findAssetInfo = null; + foreach(var buildinAsset in bundleInfo.BuildinAssets) + { + if(buildinAsset.AssetPath == assetPath) + { + findAssetInfo = buildinAsset; + break; + } + } + if (findAssetInfo == null) + { + throw new Exception($"Not found asset {assetPath} in bunlde {bundleName}"); + } + foreach(var dependAssetInfo in findAssetInfo.AllDependAssetInfos) + { + result.Add(dependAssetInfo.AssetPath); + } + } + else + { + throw new Exception($"Not found bundle : {bundleName}"); + } + return result; + } } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs index 56d21f5..2b5381d 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs @@ -47,7 +47,7 @@ namespace YooAsset.Editor List result = new List(BundleInfos.Count); foreach (var bundleInfo in BundleInfos) { - result.AddRange(bundleInfo.Assets); + result.AddRange(bundleInfo.BuildinAssets); } return result; } @@ -98,7 +98,7 @@ namespace YooAsset.Editor return TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo); } - private bool TryGetBundleInfo(string bundleFullName, out BuildBundleInfo result) + public bool TryGetBundleInfo(string bundleFullName, out BuildBundleInfo result) { foreach (var bundleInfo in BundleInfos) { @@ -188,6 +188,7 @@ namespace YooAsset.Editor if (buildAssetInfo.IsCollectAsset) continue; + // 零依赖资源 if (buildAssetInfo.DependCount == 0) { undependentAssets.Add(buildAssetInfo); @@ -274,13 +275,13 @@ namespace YooAsset.Editor bool isRawFile = bundleInfo.IsRawFile; if (isRawFile) { - if (bundleInfo.Assets.Count != 1) + if (bundleInfo.BuildinAssets.Count != 1) throw new Exception("The bundle does not support multiple raw asset : {bundleInfo.BundleName}"); continue; } // 注意:原生文件不能被其它资源文件依赖 - foreach (var assetInfo in bundleInfo.Assets) + foreach (var assetInfo in bundleInfo.BuildinAssets) { if (assetInfo.AllDependAssetInfos != null) {