From c96fa23d61e9503066bba647234d5dd562f623e1 Mon Sep 17 00:00:00 2001 From: hevinci Date: Mon, 25 Jul 2022 16:12:34 +0800 Subject: [PATCH] Update patch manifest --- .../BuildTasks/TaskCreatePatchManifest.cs | 6 +- .../Runtime/PatchSystem/PatchBundle.cs | 78 ++++++++----------- .../Runtime/PatchSystem/PatchManifest.cs | 10 ++- 3 files changed, 45 insertions(+), 49 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs index df23c11..5944376 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs @@ -28,8 +28,9 @@ namespace YooAsset.Editor // 创建新补丁清单 PatchManifest patchManifest = new PatchManifest(); - patchManifest.EnableAddressable = buildParameters.Parameters.EnableAddressable; patchManifest.ResourceVersion = buildParameters.Parameters.BuildVersion; + patchManifest.EnableAddressable = buildParameters.Parameters.EnableAddressable; + patchManifest.OutputNameStyle = (int)buildParameters.Parameters.OutputNameStyle; patchManifest.BuildinTags = buildParameters.Parameters.BuildinTags; patchManifest.BundleList = GetAllPatchBundle(buildParameters, buildMapContext, encryptionContext); patchManifest.AssetList = GetAllPatchAsset(buildParameters, buildMapContext, patchManifest); @@ -69,7 +70,6 @@ namespace YooAsset.Editor List buildinTags = buildParameters.Parameters.GetBuildinTags(); var buildMode = buildParameters.Parameters.BuildMode; - var outputNameStype = buildParameters.Parameters.OutputNameStyle; bool standardBuild = buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild; foreach (var bundleInfo in buildMapContext.BundleInfos) { @@ -83,7 +83,7 @@ namespace YooAsset.Editor bool isBuildin = IsBuildinBundle(tags, buildinTags); bool isRawFile = bundleInfo.IsRawFile; - PatchBundle patchBundle = new PatchBundle(bundleName, hash, crc32, size, (byte)outputNameStype, tags); + PatchBundle patchBundle = new PatchBundle(bundleName, hash, crc32, size, tags); patchBundle.SetFlagsValue(isEncrypted, isBuildin, isRawFile); result.Add(patchBundle); } diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs index 6211ee4..bf6631a 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs @@ -26,11 +26,6 @@ namespace YooAsset /// public long SizeBytes; - /// - /// 名字样式 - /// - public byte NameStyle; - /// /// 资源包的分类标签 /// @@ -60,52 +55,15 @@ namespace YooAsset /// /// 文件名称 /// - public string FileName - { - get - { - if (_fileName != null) - return _fileName; - - if (NameStyle == 1) - { - _fileName = Hash; - } - else if (NameStyle == 2) - { - string tempFileExtension = System.IO.Path.GetExtension(BundleName); - _fileName = $"{Hash}{tempFileExtension}"; - } - else if (NameStyle == 3) - { - string tempFileExtension = System.IO.Path.GetExtension(BundleName); - string tempBundleName = BundleName.Replace('/', '_').Replace(tempFileExtension, ""); - _fileName = $"{tempBundleName}_{Hash}"; - } - else if (NameStyle == 4) - { - string tempFileExtension = System.IO.Path.GetExtension(BundleName); - string tempBundleName = BundleName.Replace('/', '_').Replace(tempFileExtension, ""); - _fileName = $"{tempBundleName}_{Hash}{tempFileExtension}"; - } - else - { - throw new NotImplementedException(); - } - - return _fileName; - } - } - private string _fileName = null; + public string FileName { private set; get; } - public PatchBundle(string bundleName, string hash, string crc, long sizeBytes, byte nameStyle, string[] tags) + public PatchBundle(string bundleName, string hash, string crc, long sizeBytes, string[] tags) { BundleName = bundleName; Hash = hash; CRC = crc; SizeBytes = sizeBytes; - NameStyle = nameStyle; Tags = tags; } @@ -136,6 +94,38 @@ namespace YooAsset IsRawFile = value.Test(2); } + /// + /// 解析文件名称 + /// + public void ParseFileName(int nameStype) + { + if (nameStype == 1) + { + FileName = Hash; + } + else if (nameStype == 2) + { + string tempFileExtension = System.IO.Path.GetExtension(BundleName); + FileName = $"{Hash}{tempFileExtension}"; + } + else if (nameStype == 3) + { + string tempFileExtension = System.IO.Path.GetExtension(BundleName); + string tempBundleName = BundleName.Replace('/', '_').Replace(tempFileExtension, ""); + FileName = $"{tempBundleName}_{Hash}"; + } + else if (nameStype == 4) + { + string tempFileExtension = System.IO.Path.GetExtension(BundleName); + string tempBundleName = BundleName.Replace('/', '_').Replace(tempFileExtension, ""); + FileName = $"{tempBundleName}_{Hash}{tempFileExtension}"; + } + else + { + throw new NotImplementedException(); + } + } + /// /// 是否包含Tag /// diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs index 035882c..b638d7e 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs @@ -12,15 +12,20 @@ namespace YooAsset [Serializable] internal class PatchManifest { + /// + /// 资源版本号 + /// + public int ResourceVersion; + /// /// 启用可寻址资源定位 /// public bool EnableAddressable; /// - /// 资源版本号 + /// 文件名称样式 /// - public int ResourceVersion; + public int OutputNameStyle; /// /// 内置资源的标签列表(首包资源) @@ -228,6 +233,7 @@ namespace YooAsset foreach (var patchBundle in patchManifest.BundleList) { patchBundle.ParseFlagsValue(); + patchBundle.ParseFileName(patchManifest.OutputNameStyle); patchManifest.BundleDic.Add(patchBundle.BundleName, patchBundle); }