mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-24 09:40:11 +00:00
fix #590
This commit is contained in:
@@ -60,7 +60,7 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 尝试卸载指定资源的资源包(包括依赖资源)
|
/// 尝试卸载指定资源的资源包(包括依赖资源)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void TryUnloadUnusedAsset(AssetInfo assetInfo)
|
public void TryUnloadUnusedAsset(AssetInfo assetInfo, int loopCount)
|
||||||
{
|
{
|
||||||
if (assetInfo.IsInvalid)
|
if (assetInfo.IsInvalid)
|
||||||
{
|
{
|
||||||
@@ -68,34 +68,39 @@ namespace YooAsset
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 卸载主资源包加载器
|
while (loopCount > 0)
|
||||||
string mainBundleName = _bundleQuery.GetMainBundleName(assetInfo);
|
|
||||||
var mainLoader = TryGetBundleFileLoader(mainBundleName);
|
|
||||||
if (mainLoader != null)
|
|
||||||
{
|
{
|
||||||
mainLoader.TryDestroyProviders();
|
loopCount--;
|
||||||
if (mainLoader.CanDestroyLoader())
|
|
||||||
{
|
|
||||||
string bundleName = mainLoader.LoadBundleInfo.Bundle.BundleName;
|
|
||||||
mainLoader.DestroyLoader();
|
|
||||||
LoaderDic.Remove(bundleName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 卸载依赖资源包加载器
|
// 卸载主资源包加载器
|
||||||
string[] dependBundleNames = _bundleQuery.GetDependBundleNames(assetInfo);
|
string mainBundleName = _bundleQuery.GetMainBundleName(assetInfo);
|
||||||
foreach (var dependBundleName in dependBundleNames)
|
var mainLoader = TryGetBundleFileLoader(mainBundleName);
|
||||||
{
|
if (mainLoader != null)
|
||||||
var dependLoader = TryGetBundleFileLoader(dependBundleName);
|
|
||||||
if (dependLoader != null)
|
|
||||||
{
|
{
|
||||||
if (dependLoader.CanDestroyLoader())
|
mainLoader.TryDestroyProviders();
|
||||||
|
if (mainLoader.CanDestroyLoader())
|
||||||
{
|
{
|
||||||
string bundleName = dependLoader.LoadBundleInfo.Bundle.BundleName;
|
string bundleName = mainLoader.LoadBundleInfo.Bundle.BundleName;
|
||||||
dependLoader.DestroyLoader();
|
mainLoader.DestroyLoader();
|
||||||
LoaderDic.Remove(bundleName);
|
LoaderDic.Remove(bundleName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 卸载依赖资源包加载器
|
||||||
|
string[] dependBundleNames = _bundleQuery.GetDependBundleNames(assetInfo);
|
||||||
|
foreach (var dependBundleName in dependBundleNames)
|
||||||
|
{
|
||||||
|
var dependLoader = TryGetBundleFileLoader(dependBundleName);
|
||||||
|
if (dependLoader != null)
|
||||||
|
{
|
||||||
|
if (dependLoader.CanDestroyLoader())
|
||||||
|
{
|
||||||
|
string bundleName = dependLoader.LoadBundleInfo.Bundle.BundleName;
|
||||||
|
dependLoader.DestroyLoader();
|
||||||
|
LoaderDic.Remove(bundleName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -361,21 +361,21 @@ namespace YooAsset
|
|||||||
/// 资源回收
|
/// 资源回收
|
||||||
/// 说明:尝试卸载指定的资源
|
/// 说明:尝试卸载指定的资源
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void TryUnloadUnusedAsset(string location)
|
public void TryUnloadUnusedAsset(string location, int loopCount = 10)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||||
_resourceManager.TryUnloadUnusedAsset(assetInfo);
|
_resourceManager.TryUnloadUnusedAsset(assetInfo, loopCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源回收
|
/// 资源回收
|
||||||
/// 说明:尝试卸载指定的资源
|
/// 说明:尝试卸载指定的资源
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void TryUnloadUnusedAsset(AssetInfo assetInfo)
|
public void TryUnloadUnusedAsset(AssetInfo assetInfo, int loopCount = 10)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
_resourceManager.TryUnloadUnusedAsset(assetInfo);
|
_resourceManager.TryUnloadUnusedAsset(assetInfo, loopCount);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user