From ea28d3e6e1d63baf4d573dbc26f01e58535a6a5f Mon Sep 17 00:00:00 2001 From: hevinci Date: Tue, 12 Apr 2022 19:15:44 +0800 Subject: [PATCH] Simplify the concept of resource version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 简化资源版本概念 --- .../AssetBundleBuilderHelper.cs | 17 +- .../BuildReport/ReportBundleInfo.cs | 5 - .../BuildTasks/TaskCopyBuildinFiles.cs | 24 ++- .../BuildTasks/TaskCreatePatchManifest.cs | 30 ++- .../BuildTasks/TaskCreatePatchPackage.cs | 45 ++-- .../BuildTasks/TaskCreateReport.cs | 3 +- .../BuildTasks/TaskPrepare.cs | 2 +- .../VisualViewers/AssetListDebuggerViewer.cs | 14 -- .../AssetListDebuggerViewer.uxml | 1 - .../VisualViewers/BundleListDebuggerViewer.cs | 14 -- .../BundleListDebuggerViewer.uxml | 1 - .../VisualViewers/BundleListReporterViewer.cs | 14 -- .../BundleListReporterViewer.uxml | 1 - .../Loader/DependAssetBundleGrouper.cs | 1 - .../AssetSystem/Provider/BundledProvider.cs | 1 - .../Runtime/Debugger/DebugBundleInfo.cs | 5 - .../Runtime/PatchSystem/BundleInfo.cs | 14 -- .../Operations/InitializationOperation.cs | 203 ++++++++++++------ .../Operations/UpdateManifestOperation.cs | 128 ++++++----- .../UpdateStaticVersionOperation.cs | 134 ++++++++++++ .../UpdateStaticVersionOperation.cs.meta | 11 + .../Runtime/PatchSystem/PatchBundle.cs | 8 +- .../Runtime/PatchSystem/PatchCache.cs | 9 +- .../PatchSystem/PlayMode/HostPlayModeImpl.cs | 33 +-- .../PatchSystem/PlayMode/WebPlayModeImpl.cs | 12 ++ .../PlayMode/WebPlayModeImpl.cs.meta | 11 + .../Runtime/Settings/YooAssetSettings.cs | 12 +- .../Runtime/Settings/YooAssetSettingsData.cs | 16 ++ Assets/YooAsset/Runtime/Utility/YooHelper.cs | 32 --- Assets/YooAsset/Runtime/YooAssets.cs | 37 +++- 30 files changed, 516 insertions(+), 322 deletions(-) create mode 100644 Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateStaticVersionOperation.cs create mode 100644 Assets/YooAsset/Runtime/PatchSystem/Operations/UpdateStaticVersionOperation.cs.meta create mode 100644 Assets/YooAsset/Runtime/PatchSystem/PlayMode/WebPlayModeImpl.cs create mode 100644 Assets/YooAsset/Runtime/PatchSystem/PlayMode/WebPlayModeImpl.cs.meta diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs index bbc9969..fc1e8a2 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs @@ -117,11 +117,11 @@ namespace YooAsset.Editor /// - /// 从输出目录加载补丁清单文件 + /// 加载补丁清单文件 /// - internal static PatchManifest LoadPatchManifestFile(string fileDirectory) + internal static PatchManifest LoadPatchManifestFile(string fileDirectory, int resourceVersion) { - string filePath = $"{fileDirectory}/{YooAssetSettingsData.Setting.PatchManifestFileName}"; + string filePath = $"{fileDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; if (File.Exists(filePath) == false) { throw new System.Exception($"Not found patch manifest file : {filePath}"); @@ -130,5 +130,16 @@ namespace YooAsset.Editor string jsonData = FileUtility.ReadFile(filePath); return PatchManifest.Deserialize(jsonData); } + + /// + /// 获取旧的补丁清单 + /// + internal static PatchManifest GetOldPatchManifest(string pipelineOutputDirectory) + { + string staticVersionFilePath = $"{pipelineOutputDirectory}/{YooAssetSettings.VersionFileName}"; + string staticVersionContent = FileUtility.ReadFile(staticVersionFilePath); + int staticVersion = int.Parse(staticVersionContent); + return LoadPatchManifestFile(pipelineOutputDirectory, staticVersion); + } } } \ 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 2fba0c0..ee60316 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportBundleInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportBundleInfo.cs @@ -27,11 +27,6 @@ namespace YooAsset.Editor /// public long SizeBytes; - /// - /// 文件版本 - /// - public int Version; - /// /// Tags /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCopyBuildinFiles.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCopyBuildinFiles.cs index bd26edb..7d17483 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCopyBuildinFiles.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCopyBuildinFiles.cs @@ -15,21 +15,20 @@ namespace YooAsset.Editor { // 注意:我们只有在强制重建的时候才会拷贝 var buildParameters = context.GetContextObject(); - if(buildParameters.Parameters.ForceRebuild) + if (buildParameters.Parameters.ForceRebuild) { // 清空流目录 AssetBundleBuilderHelper.ClearStreamingAssetsFolder(); // 拷贝内置文件 - var pipelineOutputDirectory = buildParameters.PipelineOutputDirectory; - CopyBuildinFilesToStreaming(pipelineOutputDirectory); + CopyBuildinFilesToStreaming(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion); } } - private void CopyBuildinFilesToStreaming(string pipelineOutputDirectory) + private void CopyBuildinFilesToStreaming(string pipelineOutputDirectory, int buildVersion) { // 加载补丁清单 - PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory); + PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory, buildVersion); // 拷贝文件列表 foreach (var patchBundle in patchManifest.BundleList) @@ -45,15 +44,22 @@ namespace YooAsset.Editor // 拷贝清单文件 { - string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestFileName}"; - string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.Setting.PatchManifestFileName}"; + string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(buildVersion)}"; + string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.GetPatchManifestFileName(buildVersion)}"; EditorTools.CopyFile(sourcePath, destPath, true); } // 拷贝清单哈希文件 { - string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestHashFileName}"; - string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.Setting.PatchManifestHashFileName}"; + string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(buildVersion)}"; + string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.GetPatchManifestHashFileName(buildVersion)}"; + EditorTools.CopyFile(sourcePath, destPath, true); + } + + // 拷贝静态版本文件 + { + string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettings.VersionFileName}"; + string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettings.VersionFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs index d074821..a722b48 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs @@ -24,6 +24,8 @@ namespace YooAsset.Editor private void CreatePatchManifestFile(AssetBundleBuilder.BuildParametersContext buildParameters, BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext) { + int resourceVersion = buildParameters.Parameters.BuildVersion; + // 创建新补丁清单 PatchManifest patchManifest = new PatchManifest(); patchManifest.ResourceVersion = buildParameters.Parameters.BuildVersion; @@ -32,15 +34,21 @@ namespace YooAsset.Editor patchManifest.AssetList = GetAllPatchAsset(buildMapContext, patchManifest); // 创建补丁清单文件 - string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestFileName}"; + string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; UnityEngine.Debug.Log($"创建补丁清单文件:{manifestFilePath}"); PatchManifest.Serialize(manifestFilePath, patchManifest); // 创建补丁清单哈希文件 - string manifestHashFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestHashFileName}"; + string manifestHashFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}"; string manifestHash = HashUtility.FileMD5(manifestFilePath); UnityEngine.Debug.Log($"创建补丁清单哈希文件:{manifestHashFilePath}"); FileUtility.CreateFile(manifestHashFilePath, manifestHash); + + // 创建静态版本文件 + string staticVersionFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}"; + string staticVersion = resourceVersion.ToString(); + UnityEngine.Debug.Log($"创建静态版本文件:{staticVersionFilePath}"); + FileUtility.CreateFile(staticVersionFilePath, staticVersion); } /// @@ -54,19 +62,12 @@ namespace YooAsset.Editor // 内置标记列表 List buildinTags = buildParameters.Parameters.GetBuildinTags(); - // 加载旧补丁清单 - PatchManifest oldPatchManifest = null; - if (buildParameters.Parameters.ForceRebuild == false) - { - oldPatchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory); - } - foreach (var bundleInfo in buildMapContext.BundleInfos) { var bundleName = bundleInfo.BundleName; string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}"; string hash = HashUtility.FileMD5(filePath); - string crc = HashUtility.FileCRC32(filePath); + string crc32 = HashUtility.FileCRC32(filePath); long size = FileUtility.GetFileSize(filePath); int version = buildParameters.Parameters.BuildVersion; string[] tags = buildMapContext.GetAssetTags(bundleName); @@ -80,14 +81,7 @@ namespace YooAsset.Editor hash += bundleInfo.GetAppendExtension(); } - // 注意:如果文件没有变化使用旧版本号 - if (oldPatchManifest != null && oldPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle value)) - { - if (value.Hash == hash) - version = value.Version; - } - - PatchBundle patchBundle = new PatchBundle(bundleName, hash, crc, size, version, tags); + PatchBundle patchBundle = new PatchBundle(bundleName, hash, crc32, size, tags); patchBundle.SetFlagsValue(isEncrypted, isBuildin, isRawFile); result.Add(patchBundle); } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs index dd1065d..ca3f5e1 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs @@ -19,31 +19,40 @@ namespace YooAsset.Editor /// private void CopyPatchFiles(AssetBundleBuilder.BuildParametersContext buildParameters) { + int resourceVersion = buildParameters.Parameters.BuildVersion; string packageDirectory = buildParameters.GetPackageDirectory(); - UnityEngine.Debug.Log($"开始拷贝补丁文件到补丁包目录:{packageDirectory}"); + UnityEngine.Debug.Log($"准备开始拷贝补丁文件到补丁包目录:{packageDirectory}"); // 拷贝Report文件 { string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.ReportFileName}"; string destPath = $"{packageDirectory}/{YooAssetSettings.ReportFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); - UnityEngine.Debug.Log($"拷贝Report文件到:{destPath}"); + UnityEngine.Debug.Log($"拷贝构建报告文件到:{destPath}"); } - // 拷贝PatchManifest文件 + // 拷贝补丁清单文件 { - string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestFileName}"; - string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.PatchManifestFileName}"; + string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; + string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; EditorTools.CopyFile(sourcePath, destPath, true); - UnityEngine.Debug.Log($"拷贝PatchManifest文件到:{destPath}"); + UnityEngine.Debug.Log($"拷贝补丁清单文件到:{destPath}"); } - // 拷贝PatchManifest哈希文件 + // 拷贝补丁清单哈希文件 { - string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.PatchManifestHashFileName}"; - string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.PatchManifestHashFileName}"; + string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}"; + string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}"; EditorTools.CopyFile(sourcePath, destPath, true); - UnityEngine.Debug.Log($"拷贝PatchManifest哈希文件到:{destPath}"); + UnityEngine.Debug.Log($"拷贝补丁清单哈希文件到:{destPath}"); + } + + // 拷贝静态版本文件 + { + string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}"; + string destPath = $"{packageDirectory}/{YooAssetSettings.VersionFileName}"; + EditorTools.CopyFile(sourcePath, destPath, true); + UnityEngine.Debug.Log($"拷贝静态版本文件到:{destPath}"); } // 拷贝UnityManifest序列化文件 @@ -62,20 +71,16 @@ namespace YooAsset.Editor } // 拷贝所有补丁文件 - // 注意:拷贝的补丁文件都是需要玩家热更新的文件 int progressValue = 0; - PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory); + PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion); int patchFileTotalCount = patchManifest.BundleList.Count; foreach (var patchBundle in patchManifest.BundleList) { - if (patchBundle.Version == buildParameters.Parameters.BuildVersion) - { - string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{patchBundle.BundleName}"; - string destPath = $"{packageDirectory}/{patchBundle.Hash}"; - EditorTools.CopyFile(sourcePath, destPath, true); - UnityEngine.Debug.Log($"拷贝补丁文件到补丁包:{patchBundle.BundleName}"); - EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount); - } + string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{patchBundle.BundleName}"; + string destPath = $"{packageDirectory}/{patchBundle.Hash}"; + EditorTools.CopyFile(sourcePath, destPath, true); + UnityEngine.Debug.Log($"拷贝补丁文件到补丁包:{patchBundle.BundleName}"); + EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount); } EditorTools.ClearProgressBar(); } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs index 3f38aef..5ec5800 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs @@ -18,7 +18,7 @@ namespace YooAsset.Editor private void CreateReportFile(AssetBundleBuilder.BuildParametersContext buildParameters, BuildMapContext buildMapContext) { - PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory); + PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion); BuildReport buildReport = new BuildReport(); buildParameters.StopWatch(); @@ -79,7 +79,6 @@ namespace YooAsset.Editor 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); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs index 94f11e6..57de898 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs @@ -43,7 +43,7 @@ namespace YooAsset.Editor throw new Exception($"补丁包已经存在:{packageDirectory}"); // 检测内置资源分类标签是否一致 - PatchManifest oldPatchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory); + var oldPatchManifest = AssetBundleBuilderHelper.GetOldPatchManifest(buildParameters.PipelineOutputDirectory); if (buildParameters.Parameters.BuildinTags != oldPatchManifest.BuildinTags) throw new Exception($"增量更新时内置资源标签必须一致:{buildParameters.Parameters.BuildinTags} != {oldPatchManifest.BuildinTags}"); } diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/AssetListDebuggerViewer.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/AssetListDebuggerViewer.cs index aca234d..86fbd83 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/AssetListDebuggerViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/AssetListDebuggerViewer.cs @@ -178,16 +178,6 @@ namespace YooAsset.Editor element.Add(label); } - { - var label = new Label(); - label.name = "Label2"; - label.style.unityTextAlign = TextAnchor.MiddleLeft; - label.style.marginLeft = 3f; - //label.style.flexGrow = 1f; - label.style.width = 100; - element.Add(label); - } - { var label = new Label(); label.name = "Label3"; @@ -219,10 +209,6 @@ namespace YooAsset.Editor var label1 = element.Q