From fa0009685d904e97a3e8c2c120c2d43b7cf13b8c Mon Sep 17 00:00:00 2001 From: hevinci Date: Mon, 21 Mar 2022 14:46:43 +0800 Subject: [PATCH] Update AssetBundleBuilder --- .../AssetBundleBuilder/AssetBundleBuilder.cs | 20 +- .../BuildReport/BuildReport.cs | 5 + .../BuildReport/ReportSummary.cs | 3 + .../BuildTasks/TaskCreatePatchPackage.cs | 8 - .../BuildTasks/TaskCreateReadme.cs | 205 ------------------ .../BuildTasks/TaskCreateReadme.cs.meta | 11 - .../BuildTasks/TaskCreateReport.cs | 19 +- .../BuildTasks/TaskPrepare.cs | 3 +- 8 files changed, 46 insertions(+), 228 deletions(-) delete mode 100644 Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReadme.cs delete mode 100644 Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReadme.cs.meta diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs index 83e475b..9cd61d2 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs @@ -10,6 +10,8 @@ namespace YooAsset.Editor { public class BuildParametersContext : IContextObject { + private readonly System.Diagnostics.Stopwatch _buildWatch = new System.Diagnostics.Stopwatch(); + /// /// 构建参数 /// @@ -67,6 +69,23 @@ namespace YooAsset.Editor return opt; } + + /// + /// 获取构建的耗时(单位:秒) + /// + public int GetBuildingSeconds() + { + int seconds = (int)(_buildWatch.ElapsedMilliseconds / 1000); + return seconds; + } + public void BeginWatch() + { + _buildWatch.Start(); + } + public void StopWatch() + { + _buildWatch.Stop(); + } } private readonly BuildContext _buildContext = new BuildContext(); @@ -91,7 +110,6 @@ namespace YooAsset.Editor new TaskBuilding(), //开始执行构建 new TaskEncryption(), //加密资源文件 new TaskCreatePatchManifest(), //创建清单文件 - new TaskCreateReadme(), //创建说明文件 new TaskCreateReport(), //创建报告文件 new TaskCreatePatchPackage(), //制作补丁包 new TaskCopyBuildinFiles(), //拷贝内置文件 diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs index f59e3df..ef2d4c3 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs @@ -26,6 +26,11 @@ namespace YooAsset.Editor /// public List BundleInfos = new List(); + /// + /// 收集器信息列表 + /// + public List CollectorInfoList = new List(); + /// /// 冗余的资源列表 /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs index 92340a3..1da9e76 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs @@ -1,4 +1,6 @@ using System; +using System.Collections; +using System.Collections.Generic; using UnityEditor; namespace YooAsset.Editor @@ -62,6 +64,7 @@ namespace YooAsset.Editor // 构建结果 public int AssetFileTotalCount; + public int RedundancyAssetFileCount; public int AllBundleTotalCount; public long AllBundleTotalSize; public int BuildinBundleTotalCount; diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs index 7b59887..d8b9b71 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs @@ -22,14 +22,6 @@ namespace YooAsset.Editor string packageDirectory = buildParameters.GetPackageDirectory(); UnityEngine.Debug.Log($"开始拷贝补丁文件到补丁包目录:{packageDirectory}"); - // 拷贝Readme文件 - { - string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{ResourceSettingData.Setting.ReadmeFileName}"; - string destPath = $"{packageDirectory}/{ResourceSettingData.Setting.ReadmeFileName}"; - EditorTools.CopyFile(sourcePath, destPath, true); - UnityEngine.Debug.Log($"拷贝Readme文件到:{destPath}"); - } - // 拷贝Report文件 { string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{ResourceSettingData.Setting.ReportFileName}"; diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReadme.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReadme.cs deleted file mode 100644 index 0905e97..0000000 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReadme.cs +++ /dev/null @@ -1,205 +0,0 @@ -using System; -using System.IO; -using System.Text; -using System.Collections; -using System.Collections.Generic; - -namespace YooAsset.Editor -{ - /// - /// 创建说明文件 - /// - public class TaskCreateReadme : IBuildTask - { - void IBuildTask.Run(BuildContext context) - { - var buildParameters = context.GetContextObject(); - var buildMapContext = context.GetContextObject(); - CreateReadmeFile(buildParameters, buildMapContext); - } - - /// - /// 创建Readme文件到输出目录 - /// - private void CreateReadmeFile(AssetBundleBuilder.BuildParametersContext buildParameters, TaskGetBuildMap.BuildMapContext buildMapContext) - { - PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory); - - // 删除旧文件 - string filePath = $"{buildParameters.PipelineOutputDirectory}/{ResourceSettingData.Setting.ReadmeFileName}"; - if (File.Exists(filePath)) - File.Delete(filePath); - - UnityEngine.Debug.Log($"创建说明文件:{filePath}"); - - StringBuilder content = new StringBuilder(); - AppendData(content, $"构建时间:{DateTime.Now}"); - AppendData(content, $"构建平台:{buildParameters.Parameters.BuildTarget}"); - AppendData(content, $"构建版本:{buildParameters.Parameters.BuildVersion}"); - AppendData(content, $"自动分包:{buildParameters.Parameters.EnableAutoCollect}"); - - AppendData(content, ""); - AppendData(content, $"--着色器--"); - AppendData(content, $"IsCollectAllShaders:{AssetBundleCollectorSettingData.Setting.AutoCollectShaders}"); - AppendData(content, $"ShadersBundleName:{AssetBundleCollectorSettingData.Setting.ShadersBundleName}"); - - AppendData(content, ""); - AppendData(content, $"--配置信息--"); - for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Collectors.Count; i++) - { - AssetBundleCollectorSetting.Collector wrapper = AssetBundleCollectorSettingData.Setting.Collectors[i]; - AppendData(content, wrapper.ToString()); - } - - AppendData(content, ""); - AppendData(content, $"--构建参数--"); - AppendData(content, $"CompressOption:{buildParameters.Parameters.CompressOption}"); - AppendData(content, $"IsForceRebuild:{buildParameters.Parameters.ForceRebuild}"); - AppendData(content, $"BuildinTags:{buildParameters.Parameters.BuildinTags}"); - AppendData(content, $"IsAppendHash:{buildParameters.Parameters.AppendHash}"); - AppendData(content, $"IsDisableWriteTypeTree:{buildParameters.Parameters.DisableWriteTypeTree}"); - AppendData(content, $"IsIgnoreTypeTreeChanges:{buildParameters.Parameters.IgnoreTypeTreeChanges}"); - AppendData(content, $"IsDisableLoadAssetByFileName : {buildParameters.Parameters.DisableLoadAssetByFileName}"); - - AppendData(content, ""); - AppendData(content, $"--构建信息--"); - AppendData(content, $"参与构建的资源总数:{buildMapContext.GetAllAssets().Count}"); - GetBundleFileCountAndTotalSize(patchManifest, out int fileCount1, out long fileTotalSize1); - AppendData(content, $"构建的资源包总数:{fileCount1} 文件总大小:{fileTotalSize1 / (1024 * 1024)}MB"); - GetBuildinFileCountAndTotalSize(patchManifest, out int fileCount2, out long fileTotalSize2); - AppendData(content, $"内置的资源包总数:{fileCount2} 文件总大小:{fileTotalSize2 / (1024 * 1024)}MB"); - GetNotBuildinFileCountAndTotalSize(patchManifest, out int fileCount3, out long fileTotalSize3); - AppendData(content, $"非内置的资源包总数:{fileCount3} 文件总大小:{fileTotalSize3 / (1024 * 1024)}MB"); - GetEncryptedFileCountAndTotalSize(patchManifest, out int fileCount4, out long fileTotalSize4); - AppendData(content, $"加密的资源包总数:{fileCount4} 文件总大小:{fileTotalSize4 / (1024 * 1024)}MB"); - GetRawFileCountAndTotalSize(patchManifest, out int fileCount5, out long fileTotalSize5); - AppendData(content, $"原生的资源包总数:{fileCount5} 文件总大小:{fileTotalSize5 / (1024 * 1024)}MB"); - - AppendData(content, ""); - AppendData(content, $"--冗余列表--"); - for (int i = 0; i < buildMapContext.RedundancyAssetList.Count; i++) - { - string redundancyAssetPath = buildMapContext.RedundancyAssetList[i]; - AppendData(content, redundancyAssetPath); - } - - AppendData(content, ""); - AppendData(content, $"--构建列表--"); - for (int i = 0; i < buildMapContext.BundleInfos.Count; i++) - { - string bundleName = buildMapContext.BundleInfos[i].BundleName; - AppendData(content, bundleName); - } - - AppendData(content, ""); - AppendData(content, $"--内置文件列表--"); - foreach (var patchBundle in patchManifest.BundleList) - { - if (patchBundle.IsBuildin) - { - AppendData(content, patchBundle.BundleName); - } - } - - AppendData(content, ""); - AppendData(content, $"--非内置文件列表--"); - foreach (var patchBundle in patchManifest.BundleList) - { - if (patchBundle.IsBuildin == false) - { - AppendData(content, patchBundle.BundleName); - } - } - - AppendData(content, ""); - AppendData(content, $"--加密文件列表--"); - foreach (var patchBundle in patchManifest.BundleList) - { - if (patchBundle.IsEncrypted) - { - AppendData(content, patchBundle.BundleName); - } - } - - AppendData(content, ""); - AppendData(content, $"--原生文件列表--"); - foreach (var patchBundle in patchManifest.BundleList) - { - if (patchBundle.IsRawFile) - { - AppendData(content, patchBundle.BundleName); - } - } - - // 创建新文件 - File.WriteAllText(filePath, content.ToString(), Encoding.UTF8); - } - private void AppendData(StringBuilder sb, string data) - { - sb.Append(data); - sb.Append("\r\n"); - } - - private void GetBundleFileCountAndTotalSize(PatchManifest patchManifest, out int fileCount, out long fileBytes) - { - fileCount = patchManifest.BundleList.Count; - fileBytes = 0; - foreach (var patchBundle in patchManifest.BundleList) - { - fileBytes += patchBundle.SizeBytes; - } - } - private void GetBuildinFileCountAndTotalSize(PatchManifest patchManifest, out int fileCount, out long fileBytes) - { - fileCount = 0; - fileBytes = 0; - foreach (var patchBundle in patchManifest.BundleList) - { - if (patchBundle.IsBuildin) - { - fileCount++; - fileBytes += patchBundle.SizeBytes; - } - } - } - private void GetNotBuildinFileCountAndTotalSize(PatchManifest patchManifest, out int fileCount, out long fileBytes) - { - fileCount = 0; - fileBytes = 0; - foreach (var patchBundle in patchManifest.BundleList) - { - if (patchBundle.IsBuildin == false) - { - fileCount++; - fileBytes += patchBundle.SizeBytes; - } - } - } - private void GetEncryptedFileCountAndTotalSize(PatchManifest patchManifest, out int fileCount, out long fileBytes) - { - fileCount = 0; - fileBytes = 0; - foreach (var patchBundle in patchManifest.BundleList) - { - if (patchBundle.IsEncrypted) - { - fileCount++; - fileBytes += patchBundle.SizeBytes; - } - } - } - private void GetRawFileCountAndTotalSize(PatchManifest patchManifest, out int fileCount, out long fileBytes) - { - fileCount = 0; - fileBytes = 0; - foreach (var patchBundle in patchManifest.BundleList) - { - if (patchBundle.IsRawFile) - { - fileCount++; - fileBytes += patchBundle.SizeBytes; - } - } - } - } -} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReadme.cs.meta b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReadme.cs.meta deleted file mode 100644 index 2687bdc..0000000 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReadme.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 1660a082a6449f4429fcca15e4383f0b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs index fbd2db3..43fb035 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs @@ -20,12 +20,13 @@ namespace YooAsset.Editor { PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory); BuildReport buildReport = new BuildReport(); + buildParameters.StopWatch(); // 概述信息 { buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion; buildReport.Summary.BuildTime = DateTime.Now.ToString(); - buildReport.Summary.BuildSeconds = 0; + buildReport.Summary.BuildSeconds = buildParameters.GetBuildingSeconds(); buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget; buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion; buildReport.Summary.EnableAutoCollect = buildParameters.Parameters.EnableAutoCollect; @@ -44,6 +45,7 @@ namespace YooAsset.Editor // 构建结果 buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount; + buildReport.Summary.RedundancyAssetFileCount = buildMapContext.RedundancyAssetList.Count; buildReport.Summary.AllBundleTotalCount = GetAllBundleCount(patchManifest); buildReport.Summary.AllBundleTotalSize = GetAllBundleSize(patchManifest); buildReport.Summary.BuildinBundleTotalCount = GetBuildinBundleCount(patchManifest); @@ -52,6 +54,8 @@ namespace YooAsset.Editor buildReport.Summary.EncryptedBundleTotalSize = GetEncryptedBundleSize(patchManifest); buildReport.Summary.RawBundleTotalCount = GetRawBundleCount(patchManifest); buildReport.Summary.RawBundleTotalSize = GetRawBundleSize(patchManifest); + + } // 资源对象列表 @@ -82,8 +86,19 @@ namespace YooAsset.Editor buildReport.BundleInfos.Add(reportBundleInfo); } + // 收集器列表 + for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Collectors.Count; i++) + { + var wrapper = AssetBundleCollectorSettingData.Setting.Collectors[i]; + buildReport.CollectorInfoList.Add(wrapper.ToString()); + } + // 冗余资源列表 - buildReport.RedundancyAssetList = buildMapContext.RedundancyAssetList; + for (int i = 0; i < buildMapContext.RedundancyAssetList.Count; i++) + { + string redundancyAssetPath = buildMapContext.RedundancyAssetList[i]; + buildReport.RedundancyAssetList.Add(redundancyAssetPath); + } // 删除旧文件 string filePath = $"{buildParameters.PipelineOutputDirectory}/{ResourceSettingData.Setting.ReportFileName}"; diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs index a2adefa..f8f6c26 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs @@ -10,7 +10,8 @@ namespace YooAsset.Editor { void IBuildTask.Run(BuildContext context) { - var buildParameters = context.GetContextObject(); + var buildParameters = context.GetContextObject(); + buildParameters.BeginWatch(); // 检测构建平台是否合法 if (buildParameters.Parameters.BuildTarget == BuildTarget.NoTarget)