diff --git a/Assets/YooAsset/Runtime/InitializeParameters.cs b/Assets/YooAsset/Runtime/InitializeParameters.cs
index 24b6017..a13d556 100644
--- a/Assets/YooAsset/Runtime/InitializeParameters.cs
+++ b/Assets/YooAsset/Runtime/InitializeParameters.cs
@@ -75,6 +75,11 @@ namespace YooAsset
///
public EVerifyLevel CacheBootVerifyLevel = EVerifyLevel.Middle;
+ ///
+ /// 自动销毁不再使用的资源提供者
+ ///
+ public bool AutoDestroyAssetProvider = false;
+
///
/// 资源加载每帧处理的最大时间片段
/// 注意:默认值为MaxValue
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Loader/BundleLoaderBase.cs b/Assets/YooAsset/Runtime/ResourceManager/Loader/BundleLoaderBase.cs
index b7e7080..5ba111b 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Loader/BundleLoaderBase.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Loader/BundleLoaderBase.cs
@@ -134,7 +134,11 @@ namespace YooAsset
}
// 移除资源提供者
- Impl.RemoveBundleProviders(_removeList);
+ if (_removeList.Count > 0)
+ {
+ Impl.RemoveBundleProviders(_removeList);
+ _removeList.Clear();
+ }
}
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadSceneOperation.cs b/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadSceneOperation.cs
index 803c37c..f23b6a7 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadSceneOperation.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadSceneOperation.cs
@@ -82,6 +82,7 @@ namespace YooAsset
{
_asyncOp = SceneManager.UnloadSceneAsync(_provider.SceneObject);
_provider.ResourceMgr.UnloadSubScene(_provider.SceneName);
+ _provider.ResourceMgr.TryUnloadUnusedAsset(_provider.MainAssetInfo);
_steps = ESteps.Checking;
}
diff --git a/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs b/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs
index f83dfa9..6d72df3 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs
@@ -20,6 +20,7 @@ namespace YooAsset
private bool _simulationOnEditor;
+ private bool _autoDestroyAssetProvider;
private long _loadingMaxTimeSlice;
private IBundleQuery _bundleQuery;
private bool _isUnloadSafe = true;
@@ -49,9 +50,10 @@ namespace YooAsset
///
/// 初始化
///
- public void Initialize(bool simulationOnEditor, long loadingMaxTimeSlice, IBundleQuery bundleServices)
+ public void Initialize(bool simulationOnEditor, bool autoDestroyAssetProvider, long loadingMaxTimeSlice, IBundleQuery bundleServices)
{
_simulationOnEditor = simulationOnEditor;
+ _autoDestroyAssetProvider = autoDestroyAssetProvider;
_loadingMaxTimeSlice = loadingMaxTimeSlice;
_bundleQuery = bundleServices;
_watch = Stopwatch.StartNew();
@@ -68,6 +70,9 @@ namespace YooAsset
foreach (var loader in _loaderList)
{
loader.Update();
+
+ if (_autoDestroyAssetProvider)
+ loader.TryDestroyProviders();
}
// 更新资源提供者
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs
index f09c259..4da46b5 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/ResourcePackage.cs
@@ -146,7 +146,7 @@ namespace YooAsset
var editorSimulateModeImpl = new EditorSimulateModeImpl(PackageName);
_bundleQuery = editorSimulateModeImpl;
_playModeImpl = editorSimulateModeImpl;
- _resourceMgr.Initialize(true, parameters.LoadingMaxTimeSlice, _bundleQuery);
+ _resourceMgr.Initialize(true, parameters.AutoDestroyAssetProvider, parameters.LoadingMaxTimeSlice, _bundleQuery);
var initializeParameters = parameters as EditorSimulateModeParameters;
initializeOperation = editorSimulateModeImpl.InitializeAsync(assist, initializeParameters.SimulateManifestFilePath);
@@ -156,7 +156,7 @@ namespace YooAsset
var offlinePlayModeImpl = new OfflinePlayModeImpl(PackageName);
_bundleQuery = offlinePlayModeImpl;
_playModeImpl = offlinePlayModeImpl;
- _resourceMgr.Initialize(false, parameters.LoadingMaxTimeSlice, _bundleQuery);
+ _resourceMgr.Initialize(false, parameters.AutoDestroyAssetProvider, parameters.LoadingMaxTimeSlice, _bundleQuery);
var initializeParameters = parameters as OfflinePlayModeParameters;
initializeOperation = offlinePlayModeImpl.InitializeAsync(assist);
@@ -166,7 +166,7 @@ namespace YooAsset
var hostPlayModeImpl = new HostPlayModeImpl(PackageName);
_bundleQuery = hostPlayModeImpl;
_playModeImpl = hostPlayModeImpl;
- _resourceMgr.Initialize(false, parameters.LoadingMaxTimeSlice, _bundleQuery);
+ _resourceMgr.Initialize(false, parameters.AutoDestroyAssetProvider, parameters.LoadingMaxTimeSlice, _bundleQuery);
var initializeParameters = parameters as HostPlayModeParameters;
initializeOperation = hostPlayModeImpl.InitializeAsync(assist,
@@ -179,7 +179,7 @@ namespace YooAsset
var webPlayModeImpl = new WebPlayModeImpl(PackageName);
_bundleQuery = webPlayModeImpl;
_playModeImpl = webPlayModeImpl;
- _resourceMgr.Initialize(false, parameters.LoadingMaxTimeSlice, _bundleQuery);
+ _resourceMgr.Initialize(false, parameters.AutoDestroyAssetProvider, parameters.LoadingMaxTimeSlice, _bundleQuery);
var initializeParameters = parameters as WebPlayModeParameters;
initializeOperation = webPlayModeImpl.InitializeAsync(assist,