This commit is contained in:
何冠峰
2025-10-09 19:10:26 +08:00
parent 15005b3d30
commit 0bde506aec
4 changed files with 25 additions and 2 deletions

View File

@@ -43,6 +43,11 @@ namespace YooAsset
/// </summary>
public int BundleLoadingMaxConcurrency = int.MaxValue;
/// <summary>
/// 当资源引用计数为零的时候自动释放资源包
/// </summary>
public bool AutoUnloadBundleWhenUnused = false;
/// <summary>
/// WebGL平台强制同步加载资源对象
/// </summary>

View File

@@ -23,6 +23,11 @@ namespace YooAsset
if (IsValidWithWarning == false)
return;
Provider.ReleaseHandle(this);
// 主动卸载零引用的资源包
if (Provider.RefCount == 0)
Provider.TryUnloadBundle();
Provider = null;
}
@@ -146,11 +151,11 @@ namespace YooAsset
/// </summary>
public System.Threading.Tasks.Task Task
{
get
get
{
if (IsValidWithWarning == false)
return null;
return Provider.Task;
return Provider.Task;
}
}

View File

@@ -308,6 +308,17 @@ namespace YooAsset
}
}
/// <summary>
/// 尝试卸载资源包
/// </summary>
public void TryUnloadBundle()
{
if (_resManager.AutoUnloadBundleWhenUnused)
{
_resManager.TryUnloadUnusedAsset(MainAssetInfo, 10);
}
}
/// <summary>
/// 结束流程
/// </summary>

View File

@@ -17,6 +17,7 @@ namespace YooAsset
private int _bundleLoadingMaxConcurrency;
// 开发者配置选项
public bool AutoUnloadBundleWhenUnused { private set; get; }
public bool WebGLForceSyncLoadAsset { private set; get; }
public bool UseWeakReferenceHandle { private set; get; }
@@ -47,6 +48,7 @@ namespace YooAsset
public void Initialize(InitializeParameters parameters, IBundleQuery bundleServices)
{
_bundleLoadingMaxConcurrency = parameters.BundleLoadingMaxConcurrency;
AutoUnloadBundleWhenUnused = parameters.AutoUnloadBundleWhenUnused;
WebGLForceSyncLoadAsset = parameters.WebGLForceSyncLoadAsset;
UseWeakReferenceHandle = parameters.UseWeakReferenceHandle;
_bundleQuery = bundleServices;