From 5415d95f360cadc9170cf495aeaec20d881383af Mon Sep 17 00:00:00 2001 From: hevinci Date: Tue, 29 Nov 2022 11:06:24 +0800 Subject: [PATCH] Fix #46 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复资源包初始化失败之后,再次初始化提示异常的问题。 --- Assets/YooAsset/Runtime/AssetsPackage.cs | 17 +++++++++++++++++ Assets/YooAsset/Runtime/YooAssets.cs | 14 ++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Assets/YooAsset/Runtime/AssetsPackage.cs b/Assets/YooAsset/Runtime/AssetsPackage.cs index dcd9414..2ce48e2 100644 --- a/Assets/YooAsset/Runtime/AssetsPackage.cs +++ b/Assets/YooAsset/Runtime/AssetsPackage.cs @@ -78,6 +78,9 @@ namespace YooAsset /// public InitializationOperation InitializeAsync(InitializeParameters parameters) { + // 注意:WebGL平台因为网络原因可能会初始化失败! + ResetInitializeAfterFailed(); + // 检测初始化参数合法性 CheckInitializeParameters(parameters); @@ -127,6 +130,20 @@ namespace YooAsset initializeOperation.Completed += InitializeOperation_Completed; return initializeOperation; } + private void ResetInitializeAfterFailed() + { + if(_isInitialize && _initializeStatus == EOperationStatus.Failed) + { + _isInitialize = false; + _initializeStatus = EOperationStatus.None; + _initializeError = string.Empty; + _bundleServices = null; + _assetSystemImpl = null; + _editorSimulateModeImpl = null; + _offlinePlayModeImpl = null; + _hostPlayModeImpl = null; + } + } private void CheckInitializeParameters(InitializeParameters parameters) { if (_isInitialize) diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index b6ad3d0..4eb96f9 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -106,6 +106,18 @@ namespace YooAsset /// /// 资源包名称 public static AssetsPackage GetAssetsPackage(string packageName) + { + var package = TryGetAssetsPackage(packageName); + if (package == null) + YooLogger.Warning($"Not found assets package : {packageName}"); + return package; + } + + /// + /// 尝试获取资源包 + /// + /// 资源包名称 + public static AssetsPackage TryGetAssetsPackage(string packageName) { if (_isInitialize == false) throw new Exception($"{nameof(YooAssets)} not initialize !"); @@ -118,8 +130,6 @@ namespace YooAsset if (package.PackageName == packageName) return package; } - - YooLogger.Warning($"Not found assets package : {packageName}"); return null; }