From f8ba0c97530a969dad0fc5e4f7cdc33cf9bb15a6 Mon Sep 17 00:00:00 2001 From: hevinci Date: Fri, 24 Feb 2023 12:12:44 +0800 Subject: [PATCH] update asset system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复引用链无效的问题。 --- .../Runtime/AssetSystem/AssetSystem.cs | 4 +-- .../AssetSystem/Loader/BundleLoaderBase.cs | 34 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs index bff8c87..b935088 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs @@ -341,13 +341,13 @@ namespace YooAsset _providers.Remove(provider); } } - internal bool CheckBundleCanDestroy(int bundleID) + internal bool CheckBundleDestroyed(int bundleID) { string bundleName = BundleServices.GetBundleName(bundleID); BundleLoaderBase loader = TryGetAssetBundleLoader(bundleName); if (loader == null) return true; - return loader.CanDestroy(); + return loader.IsDestroyed; } private BundleLoaderBase CreateAssetBundleLoaderInternal(BundleInfo bundleInfo) diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleLoaderBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleLoaderBase.cs index 6a3e54e..b559029 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleLoaderBase.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/BundleLoaderBase.cs @@ -100,7 +100,18 @@ namespace YooAsset if (IsDone() == false) return false; - return RefCount <= 0; + if (RefCount > 0) + return false; + + // 检查引用链上的资源包是否已经全部销毁 + // 注意:互相引用的资源包无法卸载! + foreach (var bundleID in MainBundleInfo.Bundle.ReferenceIDs) + { + if (Impl.CheckBundleDestroyed(bundleID) == false) + return false; + } + + return true; } /// @@ -122,24 +133,15 @@ namespace YooAsset if (RefCount > _providers.Count) return; - // 条件3:检查依赖链上的资源包 - // 依赖该资源包的所有资源包可以销毁 - // 注意:互相引用的资源包无法卸载! - foreach (var bundleID in MainBundleInfo.Bundle.ReferenceIDs) - { - if (Impl.CheckBundleCanDestroy(bundleID) == false) - return; - } - // 销毁所有Providers - foreach (var provider in _providers) { - provider.Destroy(); + foreach (var provider in _providers) + { + provider.Destroy(); + } + Impl.RemoveBundleProviders(_providers); + _providers.Clear(); } - - // 从列表里移除Providers - Impl.RemoveBundleProviders(_providers); - _providers.Clear(); }