mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-14 19:40:47 +00:00
Compare commits
3 Commits
1294d1bab2
...
4c717b69db
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c717b69db | ||
|
|
d64997a0df | ||
|
|
a265b85d37 |
@@ -2,6 +2,6 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [3.0.0] - 2026-05-01
|
||||
## [3.0.0-beta] - 2026-05-09
|
||||
|
||||
beta released.
|
||||
|
||||
@@ -33,6 +33,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public bool IsDestroyed { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否已收到强制销毁请求
|
||||
/// </summary>
|
||||
public bool ForceDestroyRequested { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 引用计数
|
||||
/// </summary>
|
||||
@@ -57,6 +62,25 @@ namespace YooAsset
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (ForceDestroyRequested)
|
||||
{
|
||||
if (_steps == ESteps.CheckConcurrency)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError("Bundle loader force destroyed during package destruction.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadBundleFile)
|
||||
{
|
||||
// 注意:终止下载器
|
||||
if (_loadPackageBundleOp != null)
|
||||
_loadPackageBundleOp.ShouldAbortDownload = true;
|
||||
}
|
||||
|
||||
// 注意:其它条件的情况下,继续往下走,等底层操作自然退出。
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckConcurrency)
|
||||
{
|
||||
if (IsWaitForCompletion)
|
||||
@@ -141,8 +165,14 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 销毁资源包加载器并释放资源包
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 该方法是幂等的,重复调用不会重复释放资源。
|
||||
/// </remarks>
|
||||
public void DestroyLoader()
|
||||
{
|
||||
if (IsDestroyed)
|
||||
return;
|
||||
|
||||
IsDestroyed = true;
|
||||
|
||||
// 注意:正在加载中的任务不可以销毁
|
||||
@@ -163,10 +193,16 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 强制销毁资源包加载器(仅用于全局 Destroy 场景)
|
||||
/// 强制销毁资源包加载器
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 该方法是幂等的,仅用于全局 Destroy 场景,重复调用不会重复释放资源。
|
||||
/// </remarks>
|
||||
public void ForceDestroyLoader()
|
||||
{
|
||||
if (IsDestroyed)
|
||||
return;
|
||||
|
||||
IsDestroyed = true;
|
||||
|
||||
if (_steps == ESteps.LoadBundleFile)
|
||||
@@ -186,6 +222,14 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求强制销毁
|
||||
/// </summary>
|
||||
public void RequestForceDestroy()
|
||||
{
|
||||
ForceDestroyRequested = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以销毁
|
||||
/// </summary>
|
||||
@@ -271,26 +315,5 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试终止加载器
|
||||
/// </summary>
|
||||
public void TryAbortLoader()
|
||||
{
|
||||
if (IsDone == false)
|
||||
{
|
||||
if (_steps == ESteps.CheckConcurrency)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError("Bundle loader aborted.");
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadBundleFile)
|
||||
{
|
||||
// 注意:终止下载器
|
||||
if (_loadPackageBundleOp != null)
|
||||
_loadPackageBundleOp.ShouldAbortDownload = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace YooAsset
|
||||
None,
|
||||
CheckOptions,
|
||||
ReleaseAll,
|
||||
TryAbortLoader,
|
||||
RequestForceDestroy,
|
||||
CheckLoading,
|
||||
DestroyAll,
|
||||
Done,
|
||||
@@ -57,14 +57,15 @@ namespace YooAsset
|
||||
if (_options.ShouldReleaseHandles)
|
||||
_resourceManager.ReleaseAllHandles();
|
||||
|
||||
_steps = ESteps.TryAbortLoader;
|
||||
_steps = ESteps.RequestForceDestroy;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.TryAbortLoader)
|
||||
if (_steps == ESteps.RequestForceDestroy)
|
||||
{
|
||||
// 尝试终止所有加载任务
|
||||
// 注意:正在加载AssetBundle的任务无法终止
|
||||
_resourceManager.TryAbortAllBundleLoaders();
|
||||
// 向所有 Provider 和 BundleLoader 下发强制销毁请求
|
||||
_resourceManager.RequestForceDestroyAllProviders();
|
||||
_resourceManager.RequestForceDestroyAllBundleLoaders();
|
||||
|
||||
_steps = ESteps.CheckLoading;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,11 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public bool IsDestroyed { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否已收到强制销毁请求
|
||||
/// </summary>
|
||||
public bool ForceDestroyRequested { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 加载任务是否进行中
|
||||
/// </summary>
|
||||
@@ -127,7 +132,18 @@ namespace YooAsset
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
// 注意:未在加载中的任务可以挂起!
|
||||
if (ForceDestroyRequested)
|
||||
{
|
||||
if (IsLoading == false)
|
||||
{
|
||||
SetFail("Provider force destroyed during package destruction.");
|
||||
return;
|
||||
}
|
||||
|
||||
// 注意:已进入加载阶段则继续等待自然完成
|
||||
}
|
||||
|
||||
// 注意:未在加载中的任务可以挂起
|
||||
if (IsLoading == false)
|
||||
{
|
||||
if (RefCount <= 0)
|
||||
@@ -206,8 +222,14 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 销毁资源提供者
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 该方法是幂等的,重复调用不会重复释放资源。
|
||||
/// </remarks>
|
||||
public void DestroyProvider()
|
||||
{
|
||||
if (IsDestroyed)
|
||||
return;
|
||||
|
||||
IsDestroyed = true;
|
||||
|
||||
// 检测是否为正常销毁
|
||||
@@ -224,6 +246,14 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求强制销毁
|
||||
/// </summary>
|
||||
public void RequestForceDestroy()
|
||||
{
|
||||
ForceDestroyRequested = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否可以销毁
|
||||
/// </summary>
|
||||
|
||||
@@ -449,13 +449,24 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试终止所有 BundleLoader
|
||||
/// 向所有 Provider 下发强制销毁请求
|
||||
/// </summary>
|
||||
internal void TryAbortAllBundleLoaders()
|
||||
internal void RequestForceDestroyAllProviders()
|
||||
{
|
||||
foreach (var provider in _providerDict.Values)
|
||||
{
|
||||
provider.RequestForceDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向所有 BundleLoader 下发强制销毁请求
|
||||
/// </summary>
|
||||
internal void RequestForceDestroyAllBundleLoaders()
|
||||
{
|
||||
foreach (var loader in _bundleLoaderDict.Values)
|
||||
{
|
||||
loader.TryAbortLoader();
|
||||
loader.RequestForceDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,17 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
private readonly ResourcePackage _resourcePackage;
|
||||
private readonly ResourceManager _resourceManager;
|
||||
private readonly UnloadAllAssetsOptions _options;
|
||||
private UnloadAllAssetsOperation _unloadAllAssetsOp;
|
||||
private string _packageVersion = string.Empty;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal DestroyPackageOperation(ResourcePackage resourcePackage, UnloadAllAssetsOptions options)
|
||||
internal DestroyPackageOperation(ResourcePackage resourcePackage, ResourceManager resourceManager, UnloadAllAssetsOptions options)
|
||||
{
|
||||
_resourcePackage = resourcePackage;
|
||||
_resourceManager = resourceManager;
|
||||
_options = options;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
@@ -53,9 +56,14 @@ namespace YooAsset
|
||||
|
||||
case EOperationStatus.Succeeded:
|
||||
if (_resourcePackage.PackageValid)
|
||||
{
|
||||
_packageVersion = _resourcePackage.GetPackageVersion();
|
||||
_steps = ESteps.UnloadAllAssets;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.DestroyPackage;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -67,7 +75,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_unloadAllAssetsOp == null)
|
||||
{
|
||||
_unloadAllAssetsOp = _resourcePackage.UnloadAllAssetsAsync(_options);
|
||||
_unloadAllAssetsOp = new UnloadAllAssetsOperation(_resourceManager, _options);
|
||||
_unloadAllAssetsOp.StartOperation();
|
||||
AddChildOperation(_unloadAllAssetsOp);
|
||||
}
|
||||
@@ -89,7 +97,6 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.DestroyPackage)
|
||||
{
|
||||
// 销毁包裹
|
||||
_resourcePackage.InternalDestroy();
|
||||
|
||||
// 最后清理该包裹的异步任务
|
||||
@@ -103,7 +110,7 @@ namespace YooAsset
|
||||
/// <inheritdoc />
|
||||
protected override string InternalGetDescription()
|
||||
{
|
||||
return $"PackageVersion: {_resourcePackage.GetPackageVersion()}";
|
||||
return $"PackageVersion: {_packageVersion}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ namespace YooAsset
|
||||
public DestroyPackageOperation DestroyPackageAsync()
|
||||
{
|
||||
var options = new UnloadAllAssetsOptions(true, true);
|
||||
var operation = new DestroyPackageOperation(this, options);
|
||||
var operation = new DestroyPackageOperation(this, _resourceManager, options);
|
||||
AsyncOperationSystem.StartOperation(AsyncOperationSystem.GlobalSchedulerName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
GUILayout.Space(10);
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("Select Builtin Resource Directory", GUILayout.MaxWidth(150)))
|
||||
if (GUILayout.Button("Select Builtin Resource Directory", GUILayout.MaxWidth(250)))
|
||||
{
|
||||
string resultPath = EditorUtility.OpenFolderPanel("Find", "Assets/", "StreamingAssets");
|
||||
if (!string.IsNullOrEmpty(resultPath))
|
||||
|
||||
@@ -47,7 +47,7 @@ public class TestLoadScene
|
||||
|
||||
// 同步加载附加场景并等待
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
SceneHandle cachedHandle;
|
||||
YooAsset.SceneHandle cachedHandle;
|
||||
{
|
||||
cachedHandle = package.LoadSceneSync("scene_c", LoadSceneMode.Additive);
|
||||
yield return cachedHandle;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.tuyoogame.yooasset",
|
||||
"displayName": "YooAsset",
|
||||
"version": "3.0.0",
|
||||
"version": "3.0.0-beta",
|
||||
"unity": "2019.4",
|
||||
"description": "unity3d resources management system.",
|
||||
"author": {
|
||||
|
||||
Reference in New Issue
Block a user