From bd5ce1e6bd638c8841e3f353704ef1e9747e3ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Fri, 18 Apr 2025 18:21:24 +0800 Subject: [PATCH] perf : webgl platform use crc verify the bundle when first time downloaded MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WebGL平台首次下载会验证CRC。 --- .../DownloadWebNormalAssetBundleOperation.cs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Assets/YooAsset/Runtime/FileSystem/Operation/Internal/DownloadWebNormalAssetBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Operation/Internal/DownloadWebNormalAssetBundleOperation.cs index b58bbca9..93da0279 100644 --- a/Assets/YooAsset/Runtime/FileSystem/Operation/Internal/DownloadWebNormalAssetBundleOperation.cs +++ b/Assets/YooAsset/Runtime/FileSystem/Operation/Internal/DownloadWebNormalAssetBundleOperation.cs @@ -122,7 +122,7 @@ namespace YooAsset { if (_disableUnityWebCache) { - var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, 0); + var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, Bundle.UnityCRC); #if UNITY_2020_3_OR_NEWER downloadhandler.autoLoadAssetBundle = false; #endif @@ -132,13 +132,24 @@ namespace YooAsset { // 注意:优先从浏览器缓存里获取文件 // The file hash defining the version of the asset bundle. - uint unityCRC = Bundle.UnityCRC; Hash128 fileHash = Hash128.Parse(Bundle.FileHash); - var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, fileHash, unityCRC); + var cachedBundle = new CachedAssetBundle(Bundle.BundleName, fileHash); + if (Caching.IsVersionCached(cachedBundle)) + { + var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, cachedBundle, 0); #if UNITY_2020_3_OR_NEWER - downloadhandler.autoLoadAssetBundle = false; + downloadhandler.autoLoadAssetBundle = false; #endif - return downloadhandler; + return downloadhandler; + } + else + { + var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, cachedBundle, Bundle.UnityCRC); +#if UNITY_2020_3_OR_NEWER + downloadhandler.autoLoadAssetBundle = false; +#endif + return downloadhandler; + } } } }