diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Requester/AssetBundleWebRequest.cs b/Assets/YooAsset/Runtime/DownloadSystem/Requester/AssetBundleWebRequest.cs index 20b4ab3f..1f4642cd 100644 --- a/Assets/YooAsset/Runtime/DownloadSystem/Requester/AssetBundleWebRequest.cs +++ b/Assets/YooAsset/Runtime/DownloadSystem/Requester/AssetBundleWebRequest.cs @@ -1,4 +1,5 @@ using System.IO; +using System.Net; using UnityEngine; using UnityEngine.Networking; @@ -29,6 +30,12 @@ namespace YooAsset // 解析附加参数 _getAssetBundle = (bool)args[0]; +#if UNITY_WECHAT_GAME && !UNITY_EDITOR + uint crc = bundleInfo.Bundle.UnityCRC; + _webRequest = WeChatWASM.WXAssetBundle.GetAssetBundle(requestURL, crc); + _webRequest.disposeDownloadHandlerOnDispose = false; +#else + // 创建下载器 _webRequest = DownloadHelper.NewRequest(requestURL); if (CacheHelper.DisableUnityCacheOnWebGL) @@ -47,6 +54,8 @@ namespace YooAsset #endif _webRequest.downloadHandler = _downloadhandler; _webRequest.disposeDownloadHandlerOnDispose = true; +#endif + _webRequest.SendWebRequest(); Status = ERequestStatus.InProgress; } @@ -92,7 +101,11 @@ namespace YooAsset { if (_getAssetBundle) { +#if UNITY_WECHAT_GAME && !UNITY_EDITOR + _cacheAssetBundle = (_webRequest.downloadHandler as WeChatWASM.DownloadHandlerWXAssetBundle).assetBundle; +#else _cacheAssetBundle = _downloadhandler.assetBundle; +#endif if (_cacheAssetBundle == null) { RequestNetError = "assetBundle is null"; diff --git a/Assets/YooAsset/Runtime/ResourceManager/Loader/BundleLoaderBase.cs b/Assets/YooAsset/Runtime/ResourceManager/Loader/BundleLoaderBase.cs index 6039f89a..596c3db0 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Loader/BundleLoaderBase.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Loader/BundleLoaderBase.cs @@ -156,7 +156,11 @@ namespace YooAsset if (CacheBundle != null) { +#if UNITY_WECHAT_GAME && !UNITY_EDITOR + WeChatWASM.AssetBundleExtensions.WXUnload(CacheBundle, true); +#else CacheBundle.Unload(true); +#endif CacheBundle = null; } } diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs index de073072..64bb32ba 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/WebPlayModeImpl.cs @@ -65,13 +65,15 @@ namespace YooAsset } // 查询相关 -#if UNITY_WECHAT_GAME + // 未命中缓存的情况,微信小程序会抛出报错,日志数量多了会卡。 +#if UNITY_WECHAT_GAME && !UNITY_EDITOR private WeChatWASM.WXFileSystemManager _wxFileSystemMgr; private bool IsCachedPackageBundle(PackageBundle packageBundle) { if (_wxFileSystemMgr == null) _wxFileSystemMgr = WeChatWASM.WX.GetFileSystemManager(); - string filePath = WeChatWASM.WX.env.USER_DATA_PATH + packageBundle.FileName; + // 如果微信小游戏设置的CDN后面还有子目录,这里也要相应添加 + string filePath = System.IO.Path.Combine(WeChatWASM.WX.env.USER_DATA_PATH, "__GAME_FILE_CACHE", packageBundle.FileName); string result = _wxFileSystemMgr.AccessSync(filePath); return result.Equals("access:ok"); }