update resource manager

初始化参数增加AutoDestroyAssetProvider
pull/229/head
hevinci 2023-10-26 19:07:51 +08:00
parent 460ea091bd
commit 9418544264
5 changed files with 21 additions and 6 deletions

View File

@ -75,6 +75,11 @@ namespace YooAsset
/// </summary>
public EVerifyLevel CacheBootVerifyLevel = EVerifyLevel.Middle;
/// <summary>
/// 自动销毁不再使用的资源提供者
/// </summary>
public bool AutoDestroyAssetProvider = false;
/// <summary>
/// 资源加载每帧处理的最大时间片段
/// 注意默认值为MaxValue

View File

@ -134,7 +134,11 @@ namespace YooAsset
}
// 移除资源提供者
Impl.RemoveBundleProviders(_removeList);
if (_removeList.Count > 0)
{
Impl.RemoveBundleProviders(_removeList);
_removeList.Clear();
}
}

View File

@ -82,6 +82,7 @@ namespace YooAsset
{
_asyncOp = SceneManager.UnloadSceneAsync(_provider.SceneObject);
_provider.ResourceMgr.UnloadSubScene(_provider.SceneName);
_provider.ResourceMgr.TryUnloadUnusedAsset(_provider.MainAssetInfo);
_steps = ESteps.Checking;
}

View File

@ -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
/// <summary>
/// 初始化
/// </summary>
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();
}
// 更新资源提供者

View File

@ -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,