From abc12d2a1ddc904068875ecc2f67e12090ef2f47 Mon Sep 17 00:00:00 2001 From: hevinci Date: Sat, 26 Nov 2022 16:43:05 +0800 Subject: [PATCH] Update runtime code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加资源系统销毁方法。 --- Assets/YooAsset/Runtime/YooAssets.cs | 56 ++++++++++++---------- Assets/YooAsset/Runtime/YooAssetsDriver.cs | 8 ---- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index 08e36cb..aefac70 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -9,6 +9,7 @@ namespace YooAsset public static partial class YooAssets { private static bool _isInitialize = false; + private static GameObject _driver = null; private static readonly List _packages = new List(); /// @@ -23,13 +24,13 @@ namespace YooAsset { // 创建驱动器 _isInitialize = true; - UnityEngine.GameObject driverGo = new UnityEngine.GameObject($"[{nameof(YooAssets)}]"); - driverGo.AddComponent(); - UnityEngine.Object.DontDestroyOnLoad(driverGo); + _driver = new UnityEngine.GameObject($"[{nameof(YooAssets)}]"); + _driver.AddComponent(); + UnityEngine.Object.DontDestroyOnLoad(_driver); #if DEBUG // 添加远程调试脚本 - driverGo.AddComponent(); + _driver.AddComponent(); #endif // 初始化异步系统 @@ -37,6 +38,31 @@ namespace YooAsset } } + /// + /// 销毁资源系统 + /// + public static void Destroy() + { + if (_isInitialize) + { + OperationSystem.DestroyAll(); + DownloadSystem.DestroyAll(); + CacheSystem.ClearAll(); + + foreach (var package in _packages) + { + package.DestroyPackage(); + } + _packages.Clear(); + + if(_driver != null) + GameObject.Destroy(_driver); + + _isInitialize = false; + YooLogger.Log("YooAssets destroy all !"); + } + } + /// /// 更新资源系统 /// @@ -54,28 +80,6 @@ namespace YooAsset } } - /// - /// 销毁资源系统 - /// - internal static void Destroy() - { - if (_isInitialize) - { - OperationSystem.DestroyAll(); - DownloadSystem.DestroyAll(); - CacheSystem.ClearAll(); - - foreach (var package in _packages) - { - package.DestroyPackage(); - } - _packages.Clear(); - - _isInitialize = false; - YooLogger.Log("YooAssets destroy all !"); - } - } - /// /// 创建资源包 diff --git a/Assets/YooAsset/Runtime/YooAssetsDriver.cs b/Assets/YooAsset/Runtime/YooAssetsDriver.cs index adb28c2..4208685 100644 --- a/Assets/YooAsset/Runtime/YooAssetsDriver.cs +++ b/Assets/YooAsset/Runtime/YooAssetsDriver.cs @@ -12,14 +12,6 @@ namespace YooAsset DebugCheckDuplicateDriver(); YooAssets.Update(); } - void OnDestroy() - { - YooAssets.Destroy(); - } - void OnApplicationQuit() - { - YooAssets.Destroy(); - } [Conditional("DEBUG")] private void DebugCheckDuplicateDriver()