From a89127df1d8d9dd2dc8476e5df55df9840261649 Mon Sep 17 00:00:00 2001 From: hevinci Date: Wed, 21 Sep 2022 11:36:28 +0800 Subject: [PATCH] Update YooAssetDriver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在游戏对象销毁的时候释放YooAssets --- Assets/YooAsset/Runtime/YooAssetDriver.cs | 5 ++++ Assets/YooAsset/Runtime/YooAssets.cs | 31 +++++++++++++---------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Assets/YooAsset/Runtime/YooAssetDriver.cs b/Assets/YooAsset/Runtime/YooAssetDriver.cs index 466f5a2..96c9117 100644 --- a/Assets/YooAsset/Runtime/YooAssetDriver.cs +++ b/Assets/YooAsset/Runtime/YooAssetDriver.cs @@ -9,6 +9,11 @@ namespace YooAsset YooAssets.InternalUpdate(); } + void OnDestroy() + { + YooAssets.InternalDestroy(); + } + void OnApplicationQuit() { YooAssets.InternalDestroy(); diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index b7d7470..b82438f 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -1072,21 +1072,24 @@ namespace YooAsset #region 内部方法 internal static void InternalDestroy() { - _isInitialize = false; - _initializeError = string.Empty; - _initializeStatus = EOperationStatus.None; + if (_isInitialize) + { + _isInitialize = false; + _initializeError = string.Empty; + _initializeStatus = EOperationStatus.None; - _bundleServices = null; - _locationServices = null; - _editorSimulateModeImpl = null; - _offlinePlayModeImpl = null; - _hostPlayModeImpl = null; + _bundleServices = null; + _locationServices = null; + _editorSimulateModeImpl = null; + _offlinePlayModeImpl = null; + _hostPlayModeImpl = null; - OperationSystem.DestroyAll(); - DownloadSystem.DestroyAll(); - CacheSystem.DestroyAll(); - AssetSystem.DestroyAll(); - YooLogger.Log("YooAssets destroy all !"); + OperationSystem.DestroyAll(); + DownloadSystem.DestroyAll(); + CacheSystem.DestroyAll(); + AssetSystem.DestroyAll(); + YooLogger.Log("YooAssets destroy all !"); + } } internal static void InternalUpdate() { @@ -1136,7 +1139,7 @@ namespace YooAsset private static void DebugCheckUpdateManifest() { var loadedBundleInfos = AssetSystem.GetLoadedBundleInfos(); - if(loadedBundleInfos.Count > 0) + if (loadedBundleInfos.Count > 0) { YooLogger.Warning($"Found loaded bundle before update manifest ! Recommended to call the {nameof(ForceUnloadAllAssets)} method to release loaded bundle !"); }