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; }