From d1439da54e4ecfa7dd1d86ded453468240e962f4 Mon Sep 17 00:00:00 2001 From: hevinci Date: Fri, 15 Jul 2022 19:34:59 +0800 Subject: [PATCH] Update AssetBundleBuilder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支持可编程构建管线 --- .../AssetBundleBuilder/AssetBundleBuilder.cs | 64 +++++++++++---- .../AssetBundleBuilderSetting.cs | 5 ++ .../AssetBundleBuilderWindow.cs | 35 ++++++-- .../AssetBundleBuilderWindow.uxml | 1 + .../AssetBundleBuilder/BuildParameters.cs | 24 ++++++ .../BuildParametersContext.cs | 41 +++++++++- .../BuildReport/ReportSummary.cs | 12 ++- .../BuildTasks/TaskBuilding.cs | 1 - .../BuildTasks/TaskBuilding_SBP.cs | 82 +++++++++++++++++++ .../BuildTasks/TaskBuilding_SBP.cs.meta | 11 +++ .../BuildTasks/TaskCreatePatchManifest.cs | 63 ++++++++++++-- .../BuildTasks/TaskCreatePatchPackage.cs | 38 +++++++-- .../BuildTasks/TaskCreateReport.cs | 10 ++- .../BuildTasks/TaskVerifyBuildResult.cs | 49 ++--------- .../BuildTasks/TaskVerifyBuildResult_SBP.cs | 60 ++++++++++++++ .../TaskVerifyBuildResult_SBP.cs.meta | 11 +++ .../AssetBundleBuilder/EBuildPipeline.cs | 19 +++++ .../AssetBundleBuilder/EBuildPipeline.cs.meta | 11 +++ .../VisualViewers/ReporterSummaryViewer.cs | 5 +- Assets/YooAsset/Editor/YooAsset.Editor.asmdef | 4 +- .../Runtime/Settings/YooAssetSettings.cs | 6 ++ 21 files changed, 462 insertions(+), 90 deletions(-) create mode 100644 Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs create mode 100644 Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs.meta create mode 100644 Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs create mode 100644 Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs.meta create mode 100644 Assets/YooAsset/Editor/AssetBundleBuilder/EBuildPipeline.cs create mode 100644 Assets/YooAsset/Editor/AssetBundleBuilder/EBuildPipeline.cs.meta diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs index fe94142..4716f65 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs @@ -18,29 +18,65 @@ namespace YooAsset.Editor // 清空旧数据 _buildContext.ClearAllContext(); + // 检测构建参数是否为空 + if (buildParameters == null) + { + throw new Exception($"{nameof(buildParameters)} is null !"); + } + if (buildParameters.BuildPipeline == EBuildPipeline.ScriptBuildPipeline) + { + if (buildParameters.SBPParameters == null) + throw new Exception($"{nameof(BuildParameters.SBPParameters)} is null !"); + } + // 构建参数 var buildParametersContext = new BuildParametersContext(buildParameters); _buildContext.SetContextObject(buildParametersContext); - // 执行构建流程 - List pipeline = new List - { - new TaskPrepare(), //前期准备工作 - new TaskGetBuildMap(), //获取构建列表 - new TaskBuilding(), //开始执行构建 - new TaskVerifyBuildResult(), //验证构建结果 - new TaskEncryption(), //加密资源文件 - new TaskCreatePatchManifest(), //创建清单文件 - new TaskCreateReport(), //创建报告文件 - new TaskCreatePatchPackage(), //制作补丁包 - new TaskCopyBuildinFiles(), //拷贝内置文件 - }; - + // 是否显示LOG if (buildParameters.BuildMode == EBuildMode.SimulateBuild) BuildRunner.EnableLog = false; else BuildRunner.EnableLog = true; + // 创建构建节点 + List pipeline; + if (buildParameters.BuildPipeline == EBuildPipeline.BuiltInBuildPipeline) + { + pipeline = new List + { + new TaskPrepare(), //前期准备工作 + new TaskGetBuildMap(), //获取构建列表 + new TaskBuilding(), //开始执行构建 + new TaskVerifyBuildResult(), //验证构建结果 + new TaskEncryption(), //加密资源文件 + new TaskCreatePatchManifest(), //创建清单文件 + new TaskCreateReport(), //创建报告文件 + new TaskCreatePatchPackage(), //制作补丁包 + new TaskCopyBuildinFiles(), //拷贝内置文件 + }; + } + else if (buildParameters.BuildPipeline == EBuildPipeline.ScriptBuildPipeline) + { + pipeline = new List + { + new TaskPrepare(), //前期准备工作 + new TaskGetBuildMap(), //获取构建列表 + new TaskBuilding_SBP(), //开始执行构建 + new TaskVerifyBuildResult_SBP(), //验证构建结果 + new TaskEncryption(), //加密资源文件 + new TaskCreatePatchManifest(), //创建清单文件 + new TaskCreateReport(), //创建报告文件 + new TaskCreatePatchPackage(), //制作补丁包 + new TaskCopyBuildinFiles(), //拷贝内置文件 + }; + } + else + { + throw new NotImplementedException(); + } + + // 执行构建流程 bool succeed = BuildRunner.Run(pipeline, _buildContext); if (succeed) Debug.Log($"{buildParameters.BuildMode} pipeline build succeed !"); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs index 2380e60..1a11758 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs @@ -10,6 +10,11 @@ namespace YooAsset.Editor /// public int BuildVersion = 0; + /// + /// 构建管线 + /// + public EBuildPipeline BuildPipeline = EBuildPipeline.BuiltInBuildPipeline; + /// /// 构建模式 /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs index 4f259c2..64fcc3b 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs @@ -24,6 +24,7 @@ namespace YooAsset.Editor private TextField _buildOutputField; private IntegerField _buildVersionField; + private EnumField _buildPipelineField; private EnumField _buildModeField; private TextField _buildinTagsField; private PopupField _encryptionField; @@ -62,6 +63,17 @@ namespace YooAsset.Editor AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value; }); + // 构建管线 + _buildPipelineField = root.Q("BuildPipeline"); + _buildPipelineField.Init(AssetBundleBuilderSettingData.Setting.BuildPipeline); + _buildPipelineField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildPipeline); + _buildPipelineField.style.width = 300; + _buildPipelineField.RegisterValueChangedCallback(evt => + { + AssetBundleBuilderSettingData.Setting.BuildPipeline = (EBuildPipeline)_buildPipelineField.value; + RefreshWindow(); + }); + // 构建模式 _buildModeField = root.Q("BuildMode"); _buildModeField.Init(AssetBundleBuilderSettingData.Setting.BuildMode); @@ -165,23 +177,28 @@ namespace YooAsset.Editor /// private void ExecuteBuild() { - var buildMode = (EBuildMode)_buildModeField.value; - string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot(); BuildParameters buildParameters = new BuildParameters(); buildParameters.OutputRoot = defaultOutputRoot; buildParameters.BuildTarget = _buildTarget; - buildParameters.BuildMode = buildMode; - buildParameters.BuildVersion = _buildVersionField.value; - buildParameters.BuildinTags = _buildinTagsField.value; + buildParameters.BuildPipeline = AssetBundleBuilderSettingData.Setting.BuildPipeline; + buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode; + buildParameters.BuildVersion = AssetBundleBuilderSettingData.Setting.BuildVersion; + buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags; buildParameters.VerifyBuildingResult = true; buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable; - buildParameters.AppendFileExtension = _appendExtensionToggle.value; - buildParameters.CopyBuildinTagFiles = buildMode == EBuildMode.ForceRebuild; + buildParameters.AppendFileExtension = AssetBundleBuilderSettingData.Setting.AppendExtension; + buildParameters.CopyBuildinTagFiles = AssetBundleBuilderSettingData.Setting.BuildMode == EBuildMode.ForceRebuild; buildParameters.EncryptionServices = CreateEncryptionServicesInstance(); - buildParameters.CompressOption = (ECompressOption)_compressionField.value; + buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption; - AssetBundleBuilder builder = new AssetBundleBuilder(); + if (AssetBundleBuilderSettingData.Setting.BuildPipeline == EBuildPipeline.ScriptBuildPipeline) + { + buildParameters.SBPParameters = new BuildParameters.SBPBuildParameters(); + buildParameters.SBPParameters.WriteLinkXML = true; + } + + var builder = new AssetBundleBuilder(); bool succeed = builder.Run(buildParameters); if (succeed) { diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml index b57509e..3a1bb06 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml @@ -3,6 +3,7 @@ + diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs index 0cf9be1..321ed84 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs @@ -9,6 +9,23 @@ namespace YooAsset.Editor /// public class BuildParameters { + /// + /// SBP构建参数 + /// + public class SBPBuildParameters + { + /// + /// 生成代码防裁剪配置 + /// + public bool WriteLinkXML = true; + } + + /// + /// 可编程构建管线的参数 + /// + public SBPBuildParameters SBPParameters; + + /// /// 输出的根目录 /// @@ -19,6 +36,11 @@ namespace YooAsset.Editor /// public BuildTarget BuildTarget; + /// + /// 构建管线 + /// + public EBuildPipeline BuildPipeline; + /// /// 构建模式 /// @@ -86,4 +108,6 @@ namespace YooAsset.Editor return StringUtility.StringToStringList(BuildinTags, ';'); } } + + } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParametersContext.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParametersContext.cs index 6e190ac..f856237 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParametersContext.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParametersContext.cs @@ -40,19 +40,19 @@ namespace YooAsset.Editor } /// - /// 获取构建选项 + /// 获取内置构建管线的构建选项 /// public BuildAssetBundleOptions GetPipelineBuildOptions() { // For the new build system, unity always need BuildAssetBundleOptions.CollectDependencies and BuildAssetBundleOptions.DeterministicAssetBundle // 除非设置ForceRebuildAssetBundle标记,否则会进行增量打包 - BuildAssetBundleOptions opt = BuildAssetBundleOptions.None; - opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it. - if (Parameters.BuildMode == EBuildMode.SimulateBuild) throw new Exception("Should never get here !"); + BuildAssetBundleOptions opt = BuildAssetBundleOptions.None; + opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it. + if (Parameters.BuildMode == EBuildMode.DryRunBuild) { opt |= BuildAssetBundleOptions.DryRunBuild; @@ -77,6 +77,39 @@ namespace YooAsset.Editor return opt; } + /// + /// 获取可编程构建管线的构建参数 + /// + public UnityEditor.Build.Pipeline.BundleBuildParameters GetSBPBuildParameters() + { + if (Parameters.BuildMode == EBuildMode.SimulateBuild) + throw new Exception("Should never get here !"); + + if (Parameters.BuildMode == EBuildMode.DryRunBuild) + throw new Exception($"SBP not support {nameof(EBuildMode.DryRunBuild)} build mode !"); + + var targetGroup = BuildPipeline.GetBuildTargetGroup(Parameters.BuildTarget); + var buildParams = new UnityEditor.Build.Pipeline.BundleBuildParameters(Parameters.BuildTarget, targetGroup, PipelineOutputDirectory); + + if (Parameters.CompressOption == ECompressOption.Uncompressed) + buildParams.BundleCompression = UnityEngine.BuildCompression.Uncompressed; + else if (Parameters.CompressOption == ECompressOption.LZMA) + buildParams.BundleCompression = UnityEngine.BuildCompression.LZMA; + else if (Parameters.CompressOption == ECompressOption.LZ4) + buildParams.BundleCompression = UnityEngine.BuildCompression.LZ4; + else + throw new System.NotImplementedException(Parameters.CompressOption.ToString()); + + if (Parameters.BuildMode == EBuildMode.ForceRebuild) + buildParams.UseCache = false; + if (Parameters.DisableWriteTypeTree) + buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.DisableWriteTypeTree; + + buildParams.WriteLinkXML = Parameters.SBPParameters.WriteLinkXML; + + return buildParams; + } + /// /// 获取构建的耗时(单位:秒) /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs index cf33b7a..ef31b28 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs @@ -8,6 +8,11 @@ namespace YooAsset.Editor [Serializable] public class ReportSummary { + /// + /// YooAsset版本 + /// + public string YooVersion; + /// /// 引擎版本 /// @@ -16,7 +21,7 @@ namespace YooAsset.Editor /// /// 构建时间 /// - public string BuildTime; + public string BuildDate; /// /// 构建耗时(单位:秒) @@ -28,6 +33,11 @@ namespace YooAsset.Editor /// public BuildTarget BuildTarget; + /// + /// 构建管线 + /// + public EBuildPipeline BuildPipeline; + /// /// 构建模式 /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs index b5e06eb..f5c150f 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using System.IO; using System.Collections; using System.Collections.Generic; using UnityEditor; diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs new file mode 100644 index 0000000..8c141df --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs @@ -0,0 +1,82 @@ +using System; +using System.Linq; +using System.Collections; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +using UnityEditor.Build.Pipeline; +using UnityEditor.Build.Pipeline.Interfaces; + +namespace YooAsset.Editor +{ + [TaskAttribute("资源构建内容打包")] + public class TaskBuilding_SBP : IBuildTask + { + public class SBPBuildResultContext : IContextObject + { + public IBundleBuildResults Results; + } + + void IBuildTask.Run(BuildContext context) + { + var buildParametersContext = context.GetContextObject(); + var buildMapContext = context.GetContextObject(); + + // 模拟构建模式下跳过引擎构建 + var buildMode = buildParametersContext.Parameters.BuildMode; + if (buildMode == EBuildMode.SimulateBuild) + return; + + // 构建内容 + var buildContent = new BundleBuildContent(buildMapContext.GetPipelineBuilds()); + + // 开始构建 + IBundleBuildResults buildResults; + var buildParameters = buildParametersContext.GetSBPBuildParameters(); + var taskList = DefaultBuildTasks.Create(DefaultBuildTasks.Preset.AssetBundleBuiltInShaderExtraction); + ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList); + if (exitCode < 0) + { + throw new Exception($"构建过程中发生错误 : {exitCode}"); + } + + BuildRunner.Log("Unity引擎打包成功!"); + SBPBuildResultContext buildResultContext = new SBPBuildResultContext(); + buildResultContext.Results = buildResults; + context.SetContextObject(buildResultContext); + + // 添加Unity内置资源包信息 + if (buildResults.BundleInfos.Keys.Any(t => t == YooAssetSettings.UnityBuiltInShadersBundleName)) + { + BuildBundleInfo builtInBundleInfo = new BuildBundleInfo(YooAssetSettings.UnityBuiltInShadersBundleName); + buildMapContext.BundleInfos.Add(builtInBundleInfo); + } + + // 拷贝原生文件 + if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild) + { + CopyRawBundle(buildMapContext, buildParametersContext); + } + } + + /// + /// 拷贝原生文件 + /// + private void CopyRawBundle(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext) + { + foreach (var bundleInfo in buildMapContext.BundleInfos) + { + if (bundleInfo.IsRawFile) + { + string dest = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; + foreach (var buildAsset in bundleInfo.BuildinAssets) + { + if (buildAsset.IsRawAsset) + EditorTools.CopyFile(buildAsset.AssetPath, dest, true); + } + } + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs.meta b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs.meta new file mode 100644 index 0000000..0fc6ce6 --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1af5fed7e9f83174d868c12b41c4a79e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs index 6018224..1bc02ff 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs @@ -1,8 +1,11 @@ using System; -using System.IO; +using System.Linq; using System.Collections; using System.Collections.Generic; +using UnityEditor.Build.Pipeline; +using UnityEditor.Build.Pipeline.Interfaces; + namespace YooAsset.Editor { [TaskAttribute("创建补丁清单文件")] @@ -10,18 +13,17 @@ namespace YooAsset.Editor { void IBuildTask.Run(BuildContext context) { - var buildParameters = context.GetContextObject(); - var buildMapContext = context.GetContextObject(); - var encryptionContext = context.GetContextObject(); - CreatePatchManifestFile(buildParameters, buildMapContext, encryptionContext); + CreatePatchManifestFile(context); } /// /// 创建补丁清单文件到输出目录 /// - private void CreatePatchManifestFile(BuildParametersContext buildParameters, BuildMapContext buildMapContext, - TaskEncryption.EncryptionContext encryptionContext) + private void CreatePatchManifestFile(BuildContext context) { + var buildParameters = context.GetContextObject(); + var buildMapContext = context.GetContextObject(); + var encryptionContext = context.GetContextObject(); int resourceVersion = buildParameters.Parameters.BuildVersion; // 创建新补丁清单 @@ -32,6 +34,13 @@ namespace YooAsset.Editor patchManifest.BundleList = GetAllPatchBundle(buildParameters, buildMapContext, encryptionContext); patchManifest.AssetList = GetAllPatchAsset(buildParameters, buildMapContext, patchManifest); + // 更新Unity内置资源包的引用关系 + if (buildParameters.Parameters.BuildPipeline == EBuildPipeline.ScriptBuildPipeline) + { + var buildResultContext = context.GetContextObject(); + UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results); + } + // 创建补丁清单文件 string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; BuildRunner.Log($"创建补丁清单文件:{manifestFilePath}"); @@ -172,5 +181,45 @@ namespace YooAsset.Editor } throw new Exception($"Not found bundle name : {bundleName}"); } + + /// + /// 更新Unity内置资源包的引用关系 + /// + private void UpdateBuiltInBundleReference(PatchManifest patchManifest, IBundleBuildResults buildResults) + { + // 获取所有依赖内置资源包的资源包列表 + List builtInBundleReferenceList = new List(); + foreach (var valuePair in buildResults.BundleInfos) + { + if (valuePair.Value.Dependencies.Any(t => t == YooAssetSettings.UnityBuiltInShadersBundleName)) + builtInBundleReferenceList.Add(valuePair.Key); + } + + // 检测依赖交集并更新依赖ID + int builtInBundleId = patchManifest.BundleList.Count - 1; + foreach (var patchAsset in patchManifest.AssetList) + { + List dependBundles = GetPatchAssetAllDependBundles(patchManifest, patchAsset); + List conflictAssetPathList = dependBundles.Intersect(builtInBundleReferenceList).ToList(); + if (conflictAssetPathList.Count > 0) + { + List newDependIDs = new List(patchAsset.DependIDs); + newDependIDs.Add(builtInBundleId); + patchAsset.DependIDs = newDependIDs.ToArray(); + } + } + } + private List GetPatchAssetAllDependBundles(PatchManifest patchManifest, PatchAsset patchAsset) + { + List result = new List(); + string mainBundle = patchManifest.BundleList[patchAsset.BundleID].BundleName; + result.Add(mainBundle); + foreach (var dependID in patchAsset.DependIDs) + { + string dependBundle = patchManifest.BundleList[dependID].BundleName; + result.Add(dependBundle); + } + return result; + } } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs index a9721f3..8221232 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs @@ -54,18 +54,38 @@ namespace YooAsset.Editor EditorTools.CopyFile(sourcePath, destPath, true); } - // 拷贝UnityManifest序列化文件 + if (buildParameters.Parameters.BuildPipeline == EBuildPipeline.ScriptBuildPipeline) { - string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}"; - string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}"; - EditorTools.CopyFile(sourcePath, destPath, true); - } + // 拷贝构建日志 + { + string sourcePath = $"{buildParameters.PipelineOutputDirectory}/buildlogtep.json"; + string destPath = $"{packageDirectory}/buildlogtep.json"; + EditorTools.CopyFile(sourcePath, destPath, true); + } - // 拷贝UnityManifest文本文件 + // 拷贝代码防裁剪配置 + if (buildParameters.Parameters.SBPParameters.WriteLinkXML) + { + string sourcePath = $"{buildParameters.PipelineOutputDirectory}/link.xml"; + string destPath = $"{packageDirectory}/link.xml"; + EditorTools.CopyFile(sourcePath, destPath, true); + } + } + else { - string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest"; - string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest"; - EditorTools.CopyFile(sourcePath, destPath, true); + // 拷贝UnityManifest序列化文件 + { + string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}"; + string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}"; + EditorTools.CopyFile(sourcePath, destPath, true); + } + + // 拷贝UnityManifest文本文件 + { + string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest"; + string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest"; + EditorTools.CopyFile(sourcePath, destPath, true); + } } // 拷贝所有补丁文件 diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs index 919732d..c66fb86 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs @@ -29,14 +29,20 @@ namespace YooAsset.Editor private void CreateReportFile(BuildParametersContext buildParameters, BuildMapContext buildMapContext) { PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion); - BuildReport buildReport = new BuildReport(); + BuildReport buildReport = new BuildReport(); // 概述信息 { +#if UNITY_2019_4_OR_NEWER + UnityEditor.PackageManager.PackageInfo packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(BuildReport).Assembly); + if (packageInfo != null) + buildReport.Summary.YooVersion = packageInfo.version; +#endif buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion; - buildReport.Summary.BuildTime = DateTime.Now.ToString(); + buildReport.Summary.BuildDate = DateTime.Now.ToString(); buildReport.Summary.BuildSeconds = (int)buildParameters.GetBuildingSeconds(); buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget; + buildReport.Summary.BuildPipeline = buildParameters.Parameters.BuildPipeline; buildReport.Summary.BuildMode = buildParameters.Parameters.BuildMode; buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion; buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags; diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs index b2fc07c..4288b23 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs @@ -37,53 +37,21 @@ namespace YooAsset.Editor string[] buildedBundles = unityManifest.GetAllAssetBundles(); // 1. 过滤掉原生Bundle - List expectBundles = new List(buildedBundles.Length); - foreach(var bundleInfo in buildMapContext.BundleInfos) - { - if (bundleInfo.IsRawFile == false) - expectBundles.Add(bundleInfo); - } + string[] expectBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToArray(); - // 2. 验证数量 - if (buildedBundles.Length != expectBundles.Count) + // 2. 验证Bundle + List intersectBundleList = buildedBundles.Except(expectBundles).ToList(); + if (intersectBundleList.Count > 0) { - Debug.LogWarning($"构建过程中可能存在无效的资源,导致和预期构建的Bundle数量不一致!"); - } - - // 3. 正向验证Bundle - foreach (var bundleName in buildedBundles) - { - if (buildMapContext.IsContainsBundle(bundleName) == false) + foreach (var intersectBundle in intersectBundleList) { - throw new Exception($"Should never get here !"); + Debug.LogWarning($"差异资源包: {intersectBundle}"); } + throw new System.Exception("存在差异资源包!请查看警告信息!"); } - // 4. 反向验证Bundle + // 3. 验证Asset bool isPass = true; - foreach (var expectBundle in expectBundles) - { - bool isMatch = false; - foreach (var buildedBundle in buildedBundles) - { - if (buildedBundle == expectBundle.BundleName) - { - isMatch = true; - break; - } - } - if (isMatch == false) - { - isPass = false; - Debug.LogWarning($"没有找到预期构建的Bundle文件 : {expectBundle.BundleName}"); - } - } - if(isPass == false) - { - throw new Exception("构建结果验证没有通过,请参考警告日志!"); - } - - // 5. 验证Asset var buildMode = buildParameters.Parameters.BuildMode; if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild) { @@ -137,7 +105,6 @@ namespace YooAsset.Editor } } - // 卸载所有加载的Bundle BuildRunner.Log("构建结果验证成功!"); } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs new file mode 100644 index 0000000..0415b74 --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs @@ -0,0 +1,60 @@ +using System; +using System.Linq; +using System.IO; +using System.Collections; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; +using UnityEditor.Build.Pipeline.Interfaces; + +namespace YooAsset.Editor +{ + [TaskAttribute("验证构建结果")] + public class TaskVerifyBuildResult_SBP : IBuildTask + { + void IBuildTask.Run(BuildContext context) + { + var buildParametersContext = context.GetContextObject(); + + // 模拟构建模式下跳过验证 + if (buildParametersContext.Parameters.BuildMode == EBuildMode.SimulateBuild) + return; + + // 验证构建结果 + if (buildParametersContext.Parameters.VerifyBuildingResult) + { + var buildResultContext = context.GetContextObject(); + VerifyingBuildingResult(context, buildResultContext.Results); + } + } + + /// + /// 验证构建结果 + /// + private void VerifyingBuildingResult(BuildContext context, IBundleBuildResults buildResults) + { + var buildParameters = context.GetContextObject(); + var buildMapContext = context.GetContextObject(); + + // 1. 移除特定Bundle + List buildedBundles = buildResults.BundleInfos.Keys.ToList(); + buildedBundles.Remove(YooAssetSettings.UnityBuiltInShadersBundleName); + + // 2. 过滤掉原生Bundle + List expectBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToList(); + + // 3. 验证Bundle + List intersectBundleList = buildedBundles.Except(expectBundles).ToList(); + if (intersectBundleList.Count > 0) + { + foreach (var intersectBundle in intersectBundleList) + { + Debug.LogWarning($"差异资源包: {intersectBundle}"); + } + throw new System.Exception("存在差异资源包!请查看警告信息!"); + } + + BuildRunner.Log("构建结果验证成功!"); + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs.meta b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs.meta new file mode 100644 index 0000000..f74469c --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 16aa7c2c37209a043b4f33d7854047c6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/EBuildPipeline.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/EBuildPipeline.cs new file mode 100644 index 0000000..8beebc2 --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/EBuildPipeline.cs @@ -0,0 +1,19 @@ + +namespace YooAsset.Editor +{ + /// + /// 构建管线类型 + /// + public enum EBuildPipeline + { + /// + /// 传统内置构建管线 + /// + BuiltInBuildPipeline, + + /// + /// 可编程构建管线 + /// + ScriptBuildPipeline, + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/EBuildPipeline.cs.meta b/Assets/YooAsset/Editor/AssetBundleBuilder/EBuildPipeline.cs.meta new file mode 100644 index 0000000..ec277dd --- /dev/null +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/EBuildPipeline.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e53e56a0f6b01dd4c933249d2bda8d78 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterSummaryViewer.cs b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterSummaryViewer.cs index 6291c1b..ad8506c 100644 --- a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterSummaryViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterSummaryViewer.cs @@ -58,10 +58,13 @@ namespace YooAsset.Editor _buildReport = buildReport; _items.Clear(); + + _items.Add(new ItemWrapper("YooAsset版本", buildReport.Summary.YooVersion)); _items.Add(new ItemWrapper("引擎版本", buildReport.Summary.UnityVersion)); - _items.Add(new ItemWrapper("构建时间", buildReport.Summary.BuildTime)); + _items.Add(new ItemWrapper("构建时间", buildReport.Summary.BuildDate)); _items.Add(new ItemWrapper("构建耗时", $"{buildReport.Summary.BuildSeconds}秒")); _items.Add(new ItemWrapper("构建平台", $"{buildReport.Summary.BuildTarget}")); + _items.Add(new ItemWrapper("构建管线", $"{buildReport.Summary.BuildPipeline}")); _items.Add(new ItemWrapper("构建模式", $"{buildReport.Summary.BuildMode}")); _items.Add(new ItemWrapper("构建版本", $"{buildReport.Summary.BuildVersion}")); _items.Add(new ItemWrapper("内置资源标签", $"{buildReport.Summary.BuildinTags}")); diff --git a/Assets/YooAsset/Editor/YooAsset.Editor.asmdef b/Assets/YooAsset/Editor/YooAsset.Editor.asmdef index 9f1d318..d9de413 100644 --- a/Assets/YooAsset/Editor/YooAsset.Editor.asmdef +++ b/Assets/YooAsset/Editor/YooAsset.Editor.asmdef @@ -2,7 +2,9 @@ "name": "YooAsset.Editor", "rootNamespace": "", "references": [ - "YooAsset" + "YooAsset", + "Unity.ScriptableBuildPipeline", + "Unity.ScriptableBuildPipeline.Editor" ], "includePlatforms": [ "Editor" diff --git a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs index a21f914..9325c37 100644 --- a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs +++ b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs @@ -25,6 +25,7 @@ namespace YooAsset /// public string UnityManifestFileName = "UnityManifest"; + /// /// 构建输出的报告文件 /// @@ -34,5 +35,10 @@ namespace YooAsset /// 静态版本文件 /// public const string VersionFileName = "StaticVersion.bytes"; + + /// + /// Unity内置着色器资源包名称 + /// + public const string UnityBuiltInShadersBundleName = "UnityBuiltInShaders.bundle"; } } \ No newline at end of file