From 775c72484009a04cc7158e71d27551a8f46a1373 Mon Sep 17 00:00:00 2001 From: hevinci Date: Wed, 27 Apr 2022 11:02:30 +0800 Subject: [PATCH] Update AssetBundleBuilder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AssetBundleBuilder界面增加演练构建选项。 构建文件名增加版本信息。 --- .../AssetBundleBuilder/AssetBundleBuilder.cs | 3 +++ .../AssetBundleBuilderSetting.cs | 5 +++++ .../AssetBundleBuilderWindow.cs | 21 ++++++++++++++++++- .../AssetBundleBuilderWindow.uxml | 1 + .../BuildTasks/TaskCreatePatchPackage.cs | 5 +++-- .../BuildTasks/TaskCreateReport.cs | 2 +- .../BuildTasks/TaskPrepare.cs | 4 ++-- .../Runtime/Settings/YooAssetSettings.cs | 2 +- .../Runtime/Settings/YooAssetSettingsData.cs | 8 +++++++ 9 files changed, 44 insertions(+), 7 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs index 28845ee..1d5e845 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs @@ -26,7 +26,10 @@ namespace YooAsset.Editor public BuildParametersContext(BuildParameters parameters) { Parameters = parameters; + PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget); + if (parameters.DryRunBuild) + PipelineOutputDirectory += "_DryRunBuild"; } /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs index a902fba..9f11e5f 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs @@ -30,6 +30,11 @@ namespace YooAsset.Editor /// public bool ForceRebuild = false; + /// + /// 演练构建 + /// + public bool DryRunBuild = false; + /// /// 内置标签 /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs index 9bd535f..8615626 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs @@ -29,6 +29,7 @@ namespace YooAsset.Editor private PopupField _encryptionField; private Toggle _appendExtensionToggle; private Toggle _forceRebuildToggle; + private Toggle _dryRunBuildToggle; private TextField _buildTagsTxt; @@ -73,6 +74,7 @@ namespace YooAsset.Editor _compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption); _compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption); _compressionField.style.width = 300; + _compressionField.SetEnabled(AssetBundleBuilderSettingData.Setting.DryRunBuild == false); _compressionField.RegisterValueChangedCallback(evt => { AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value; @@ -94,6 +96,7 @@ namespace YooAsset.Editor _encryptionField = new PopupField(_encryptionServicesClassNames, defaultIndex); _encryptionField.label = "Encryption"; _encryptionField.style.width = 300; + _encryptionField.SetEnabled(AssetBundleBuilderSettingData.Setting.DryRunBuild == false); _encryptionField.RegisterValueChangedCallback(evt => { AssetBundleBuilderSettingData.Setting.EncyptionClassName = _encryptionField.value; @@ -105,12 +108,14 @@ namespace YooAsset.Editor _encryptionField = new PopupField(); _encryptionField.label = "Encryption"; _encryptionField.style.width = 300; + _encryptionField.SetEnabled(AssetBundleBuilderSettingData.Setting.DryRunBuild == false); encryptionContainer.Add(_encryptionField); } // 附加后缀格式 _appendExtensionToggle = root.Q("AppendExtension"); _appendExtensionToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.AppendExtension); + _appendExtensionToggle.SetEnabled(AssetBundleBuilderSettingData.Setting.DryRunBuild == false); _appendExtensionToggle.RegisterValueChangedCallback(evt => { AssetBundleBuilderSettingData.Setting.AppendExtension = _appendExtensionToggle.value; @@ -119,12 +124,25 @@ namespace YooAsset.Editor // 强制构建 _forceRebuildToggle = root.Q("ForceRebuild"); _forceRebuildToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.ForceRebuild); + _forceRebuildToggle.SetEnabled(AssetBundleBuilderSettingData.Setting.DryRunBuild == false); _forceRebuildToggle.RegisterValueChangedCallback(evt => { AssetBundleBuilderSettingData.Setting.ForceRebuild = _forceRebuildToggle.value; _buildTagsTxt.SetEnabled(_forceRebuildToggle.value); }); + // 演练构建 + _dryRunBuildToggle = root.Q("DryRunBuild"); + _dryRunBuildToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.DryRunBuild); + _dryRunBuildToggle.RegisterValueChangedCallback(evt => + { + AssetBundleBuilderSettingData.Setting.DryRunBuild = _dryRunBuildToggle.value; + _compressionField.SetEnabled(_dryRunBuildToggle.value == false); + _encryptionField.SetEnabled(_dryRunBuildToggle.value == false); + _appendExtensionToggle.SetEnabled(_dryRunBuildToggle.value == false); + _forceRebuildToggle.SetEnabled(_dryRunBuildToggle.value == false); + }); + // 内置标签 _buildTagsTxt = root.Q("BuildinTags"); _buildTagsTxt.SetEnabled(_forceRebuildToggle.value); @@ -188,6 +206,7 @@ namespace YooAsset.Editor buildParameters.AppendFileExtension = _appendExtensionToggle.value; buildParameters.EncryptionServices = CreateEncryptionServicesInstance(); buildParameters.ForceRebuild = _forceRebuildToggle.value; + buildParameters.DryRunBuild = _dryRunBuildToggle.value; buildParameters.BuildinTags = _buildTagsTxt.value; AssetBundleBuilder builder = new AssetBundleBuilder(); @@ -198,7 +217,7 @@ namespace YooAsset.Editor /// 获取加密类的类型列表 /// private List GetEncryptionServicesClassTypes() - { + { TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom(); List classTypes = collection.ToList(); return classTypes; diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml index 4fd6a70..9062cff 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml @@ -7,6 +7,7 @@ + diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs index bc0eedc..546f910 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs @@ -28,8 +28,9 @@ namespace YooAsset.Editor // 拷贝Report文件 { - string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.ReportFileName}"; - string destPath = $"{packageDirectory}/{YooAssetSettings.ReportFileName}"; + string reportFileName = YooAssetSettingsData.GetReportFileName(buildParameters.Parameters.BuildVersion); + string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{reportFileName}"; + string destPath = $"{packageDirectory}/{reportFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); UnityEngine.Debug.Log($"拷贝构建报告文件到:{destPath}"); } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs index e472f62..703607a 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs @@ -86,7 +86,7 @@ namespace YooAsset.Editor } // 删除旧文件 - string filePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.ReportFileName}"; + string filePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetReportFileName(buildParameters.Parameters.BuildVersion)}"; if (File.Exists(filePath)) File.Delete(filePath); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs index 57de898..f8a9a55 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs @@ -26,7 +26,7 @@ namespace YooAsset.Editor throw new Exception("输出目录不能为空"); // 增量更新时候的必要检测 - if (buildParameters.Parameters.ForceRebuild == false) + if (buildParameters.Parameters.DryRunBuild == false && buildParameters.Parameters.ForceRebuild == false) { // 检测历史版本是否存在 if (AssetBundleBuilderHelper.HasAnyPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot) == false) @@ -49,7 +49,7 @@ namespace YooAsset.Editor } // 如果是强制重建 - if (buildParameters.Parameters.ForceRebuild) + if (buildParameters.Parameters.DryRunBuild == false && buildParameters.Parameters.ForceRebuild) { // 删除平台总目录 string platformDirectory = $"{buildParameters.Parameters.OutputRoot}/{buildParameters.Parameters.BuildTarget}"; diff --git a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs index 3d2e80d..a21f914 100644 --- a/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs +++ b/Assets/YooAsset/Runtime/Settings/YooAssetSettings.cs @@ -28,7 +28,7 @@ namespace YooAsset /// /// 构建输出的报告文件 /// - public const string ReportFileName = "BuildReport.json"; + public const string ReportFileName = "BuildReport"; /// /// 静态版本文件 diff --git a/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs b/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs index f4dc0b3..7c4b27d 100644 --- a/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs +++ b/Assets/YooAsset/Runtime/Settings/YooAssetSettingsData.cs @@ -32,6 +32,14 @@ namespace YooAsset } } + /// + /// 获取构建报告文件名 + /// + public static string GetReportFileName(int resourceVersion) + { + return $"{YooAssetSettings.ReportFileName}_{resourceVersion}.json"; + } + /// /// 获取补丁清单文件完整名称 ///