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