From d7ae52160b1064a36ac5b7b59c526ce21a09bb79 Mon Sep 17 00:00:00 2001 From: hevinci Date: Wed, 7 Dec 2022 11:26:08 +0800 Subject: [PATCH] update runtime logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化了补丁清单解析。 --- .../Runtime/PatchSystem/PatchBundle.cs | 2 +- .../Runtime/PatchSystem/PatchManifest.cs | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs index 45aaee1..fe21a4f 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs @@ -120,7 +120,7 @@ namespace YooAsset { _packageName = packageName; _cacheKey = $"{packageName}-{FileHash}"; - _fileName = PatchManifest.CreateBundleFileName(nameStype, BundleName, FileHash); + _fileName = PatchManifest.CreateBundleFileName(nameStype, BundleName, FileHash, IsRawFile); } /// diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs index dae56dd..0a0c1ae 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Text; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -407,10 +408,13 @@ namespace YooAsset } + [ThreadStatic] + private static StringBuilder _cacheBuilder = new StringBuilder(1024); + /// /// 生成Bundle文件的正式名称 /// - public static string CreateBundleFileName(int nameStype, string bundleName, string fileHash) + public static string CreateBundleFileName(int nameStype, string bundleName, string fileHash, bool isRawFile) { if (nameStype == 1) { @@ -418,24 +422,26 @@ namespace YooAsset } else if (nameStype == 2) { - string tempFileExtension = System.IO.Path.GetExtension(bundleName); - return $"{fileHash}{tempFileExtension}"; - } - else if (nameStype == 3) - { - string tempFileExtension = System.IO.Path.GetExtension(bundleName); - string tempBundleName = bundleName.Replace('/', '_').Replace(tempFileExtension, ""); - return $"{tempBundleName}_{fileHash}"; + _cacheBuilder.Clear(); + _cacheBuilder.Append(fileHash); + _cacheBuilder.Append("."); + if (isRawFile) + _cacheBuilder.Append(YooAssetSettingsData.Setting.RawFileVariant); + else + _cacheBuilder.Append(YooAssetSettingsData.Setting.AssetBundleFileVariant); + return _cacheBuilder.ToString(); } else if (nameStype == 4) { - string tempFileExtension = System.IO.Path.GetExtension(bundleName); - string tempBundleName = bundleName.Replace('/', '_').Replace(tempFileExtension, ""); - return $"{tempBundleName}_{fileHash}{tempFileExtension}"; + _cacheBuilder.Clear(); + _cacheBuilder.Append(fileHash); + _cacheBuilder.Append("_"); + _cacheBuilder.Append(bundleName); + return _cacheBuilder.ToString(); } else { - throw new NotImplementedException(); + throw new NotImplementedException($"Invalid nameStype {nameStype}"); } } }