From 665a16fe6054cdbaaaf23c6f6f4e2a3c8c43537a Mon Sep 17 00:00:00 2001 From: hevinci Date: Mon, 2 May 2022 23:15:09 +0800 Subject: [PATCH] Support fast build mode. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支持快速构建模式,真实的实现EditorPlayMode的运行时环境。 --- .../AssetBundleBuilder/AssetBundleBuilder.cs | 24 ++- .../AssetBundleBuilderSetting.cs | 25 ++- .../AssetBundleBuilderWindow.cs | 147 ++++++++---------- .../AssetBundleBuilderWindow.uxml | 5 +- .../AssetBundleRuntimeBuilder.cs | 45 ++++++ .../AssetBundleRuntimeBuilder.cs.meta} | 0 .../AssetBundleBuilder/BuildMapCreater.cs | 2 +- .../AssetBundleBuilder/BuildParameters.cs | 44 +++--- .../BuildReport/ReportSummary.cs | 13 +- .../BuildSystem/BuildRunner.cs | 15 +- .../BuildTasks/TaskBuilding.cs | 9 +- .../BuildTasks/TaskCopyBuildinFiles.cs | 4 +- .../BuildTasks/TaskCreatePatchManifest.cs | 43 ++--- .../BuildTasks/TaskCreatePatchPackage.cs | 5 +- .../BuildTasks/TaskCreateReport.cs | 7 +- .../BuildTasks/TaskEncryption.cs | 9 +- .../BuildTasks/TaskGetBuildMap.cs | 2 +- .../BuildTasks/TaskPrepare.cs | 9 +- .../BuildTasks/TaskVerifyBuildResult.cs | 11 +- .../Editor/AssetBundleBuilder/EBuildMode.cs | 29 ++++ .../AssetBundleBuilder/EBuildMode.cs.meta} | 2 +- .../AssetBundleCollector.cs | 3 + .../AssetBundleGrouperRuntimeSupport.cs | 99 ------------ .../AssetBundleGrouperWindow.cs | 2 +- .../VisualViewers/SummaryReporterViewer.cs | 6 +- .../Operations/RawFileOperation.cs | 4 +- .../Runtime/PatchSystem/BundleInfo.cs | 18 +++ .../Operations/InitializationOperation.cs | 42 ++++- .../Runtime/PatchSystem/PatchManifest.cs | 79 +++++++--- .../PlayMode/EditorPlayModeHelper.cs} | 18 ++- .../PlayMode/EditorPlayModeHelper.cs.meta | 11 ++ .../PlayMode/EditorPlayModeImpl.cs | 34 ++-- .../PatchSystem/PlayMode/HostPlayModeImpl.cs | 4 +- .../PlayMode/OfflinePlayModeImpl.cs | 4 +- .../Runtime/Services/IBundleServices.cs | 4 +- .../Runtime/Services/ILocationServices.cs | 2 +- .../AddressLocationServices.cs | 22 +-- .../DefaultLocationServices.cs | 27 +--- Assets/YooAsset/Runtime/YooAssets.cs | 46 ++++-- 39 files changed, 492 insertions(+), 383 deletions(-) create mode 100644 Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleRuntimeBuilder.cs rename Assets/YooAsset/Editor/{AssetBundleGrouper/AssetBundleGrouperRuntimeSupport.cs.meta => AssetBundleBuilder/AssetBundleRuntimeBuilder.cs.meta} (100%) create mode 100644 Assets/YooAsset/Editor/AssetBundleBuilder/EBuildMode.cs rename Assets/YooAsset/{Runtime/Services/LocationServices/LocationServicesHelper.cs.meta => Editor/AssetBundleBuilder/EBuildMode.cs.meta} (83%) delete mode 100644 Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperRuntimeSupport.cs rename Assets/YooAsset/Runtime/{Services/LocationServices/LocationServicesHelper.cs => PatchSystem/PlayMode/EditorPlayModeHelper.cs} (53%) create mode 100644 Assets/YooAsset/Runtime/PatchSystem/PlayMode/EditorPlayModeHelper.cs.meta diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs index 1d5e845..9c66058 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs @@ -28,8 +28,10 @@ namespace YooAsset.Editor Parameters = parameters; PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget); - if (parameters.DryRunBuild) - PipelineOutputDirectory += "_DryRunBuild"; + if (parameters.BuildMode == EBuildMode.DryRunBuild) + PipelineOutputDirectory += $"_{EBuildMode.DryRunBuild}"; + else if(parameters.BuildMode == EBuildMode.FastRunBuild) + PipelineOutputDirectory += $"_{EBuildMode.FastRunBuild}"; } /// @@ -51,7 +53,12 @@ namespace YooAsset.Editor BuildAssetBundleOptions opt = BuildAssetBundleOptions.None; opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it. - if (Parameters.DryRunBuild) + if (Parameters.BuildMode == EBuildMode.FastRunBuild) + { + throw new Exception("Should never get here !"); + } + + if (Parameters.BuildMode == EBuildMode.DryRunBuild) { opt |= BuildAssetBundleOptions.DryRunBuild; return opt; @@ -62,7 +69,7 @@ namespace YooAsset.Editor else if (Parameters.CompressOption == ECompressOption.LZ4) opt |= BuildAssetBundleOptions.ChunkBasedCompression; - if (Parameters.ForceRebuild) + if (Parameters.BuildMode == EBuildMode.ForceRebuild) opt |= BuildAssetBundleOptions.ForceRebuildAssetBundle; //Force rebuild the asset bundles if (Parameters.AppendHash) opt |= BuildAssetBundleOptions.AppendHashToAssetBundleName; //Append the hash to the assetBundle name @@ -125,11 +132,16 @@ namespace YooAsset.Editor new TaskCopyBuildinFiles(), //拷贝内置文件 }; + if (buildParameters.BuildMode == EBuildMode.FastRunBuild) + BuildRunner.EnableLog = false; + else + BuildRunner.EnableLog = true; + bool succeed = BuildRunner.Run(pipeline, _buildContext); if (succeed) - Debug.Log($"构建成功!"); + Debug.Log($"{buildParameters.BuildMode}模式构建成功!"); else - Debug.LogWarning($"构建失败!"); + Debug.LogWarning($"{buildParameters.BuildMode}模式构建失败!"); return succeed; } } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs index 9f11e5f..47593da 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs @@ -10,6 +10,16 @@ namespace YooAsset.Editor /// public int BuildVersion = 0; + /// + /// 构建模式 + /// + public EBuildMode BuildMode = EBuildMode.ForceRebuild; + + /// + /// 内置资源标签 + /// + public string BuildTags = string.Empty; + /// /// 压缩方式 /// @@ -24,20 +34,5 @@ namespace YooAsset.Editor /// 附加后缀格式 /// public bool AppendExtension = false; - - /// - /// 强制构建 - /// - public bool ForceRebuild = false; - - /// - /// 演练构建 - /// - public bool DryRunBuild = false; - - /// - /// 内置标签 - /// - public string BuildTags = string.Empty; } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs index 6e87bf9..ea76a1e 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs @@ -22,15 +22,13 @@ namespace YooAsset.Editor private List _encryptionServicesClassTypes; private List _encryptionServicesClassNames; - private TextField _buildOutputTxt; + private TextField _buildOutputField; private IntegerField _buildVersionField; - private EnumField _compressionField; + private EnumField _buildModeField; + private TextField _buildTagsField; private PopupField _encryptionField; + private EnumField _compressionField; private Toggle _appendExtensionToggle; - private Toggle _forceRebuildToggle; - private Toggle _dryRunBuildToggle; - private TextField _buildTagsTxt; - public void CreateGUI() { @@ -56,9 +54,9 @@ namespace YooAsset.Editor // 输出目录 string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot(); string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(defaultOutputRoot, _buildTarget); - _buildOutputTxt = root.Q("BuildOutput"); - _buildOutputTxt.SetValueWithoutNotify(pipelineOutputDirectory); - _buildOutputTxt.SetEnabled(false); + _buildOutputField = root.Q("BuildOutput"); + _buildOutputField.SetValueWithoutNotify(pipelineOutputDirectory); + _buildOutputField.SetEnabled(false); // 构建版本 _buildVersionField = root.Q("BuildVersion"); @@ -68,34 +66,33 @@ namespace YooAsset.Editor AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value; }); - // 压缩方式 - _compressionField = root.Q("Compression"); - _compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption); - _compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption); - _compressionField.style.width = 300; - _compressionField.SetEnabled(AssetBundleBuilderSettingData.Setting.DryRunBuild == false); - _compressionField.RegisterValueChangedCallback(evt => + // 构建模式 + _buildModeField = root.Q("BuildMode"); + _buildModeField.Init(AssetBundleBuilderSettingData.Setting.BuildMode); + _buildModeField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildMode); + _buildModeField.style.width = 300; + _buildModeField.RegisterValueChangedCallback(evt => { - AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value; + AssetBundleBuilderSettingData.Setting.BuildMode = (EBuildMode)_buildModeField.value; + RefreshWindow(); + }); + + // 内置资源标签 + _buildTagsField = root.Q("BuildinTags"); + _buildTagsField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags); + _buildTagsField.RegisterValueChangedCallback(evt => + { + AssetBundleBuilderSettingData.Setting.BuildTags = _buildTagsField.value; }); // 加密方法 var encryptionContainer = root.Q("EncryptionContainer"); if (_encryptionServicesClassNames.Count > 0) { - int defaultIndex = 0; - for (int index = 0; index < _encryptionServicesClassNames.Count; index++) - { - if (_encryptionServicesClassNames[index] == AssetBundleBuilderSettingData.Setting.EncyptionClassName) - { - defaultIndex = index; - break; - } - } + int defaultIndex = GetEncryptionDefaultIndex(AssetBundleBuilderSettingData.Setting.EncyptionClassName); _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; @@ -107,53 +104,32 @@ namespace YooAsset.Editor _encryptionField = new PopupField(); _encryptionField.label = "Encryption"; _encryptionField.style.width = 300; - _encryptionField.SetEnabled(AssetBundleBuilderSettingData.Setting.DryRunBuild == false); encryptionContainer.Add(_encryptionField); } + // 压缩方式 + _compressionField = root.Q("Compression"); + _compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption); + _compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption); + _compressionField.style.width = 300; + _compressionField.RegisterValueChangedCallback(evt => + { + AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value; + }); + // 附加后缀格式 _appendExtensionToggle = root.Q("AppendExtension"); _appendExtensionToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.AppendExtension); - _appendExtensionToggle.SetEnabled(AssetBundleBuilderSettingData.Setting.DryRunBuild == false); _appendExtensionToggle.RegisterValueChangedCallback(evt => { AssetBundleBuilderSettingData.Setting.AppendExtension = _appendExtensionToggle.value; }); - // 强制构建 - _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); - _buildTagsTxt.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags); - _buildTagsTxt.RegisterValueChangedCallback(evt => - { - AssetBundleBuilderSettingData.Setting.BuildTags = _buildTagsTxt.value; - }); - // 构建按钮 var buildButton = root.Q