From 6038e7acd65c90400f28ff1cf5864473186f950f Mon Sep 17 00:00:00 2001 From: hevinci <hevinci@hotmail.com> Date: Sat, 3 Dec 2022 19:13:11 +0800 Subject: [PATCH] Update asset system --- .../Handles/AssetOperationHandle.cs | 51 +++++++++++-------- .../Handles/OperationHandleBase.cs | 15 +----- .../Handles/RawFileOperationHandle.cs | 15 ++++-- .../Handles/SubAssetsOperationHandle.cs | 39 ++++++++------ 4 files changed, 67 insertions(+), 53 deletions(-) diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs index 2bbc916..f9f9451 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/AssetOperationHandle.cs @@ -1,9 +1,10 @@ -using UnityEngine; +using System; using System.Collections.Generic; +using UnityEngine; namespace YooAsset { - public sealed class AssetOperationHandle : OperationHandleBase + public sealed class AssetOperationHandle : OperationHandleBase, IDisposable { private System.Action<AssetOperationHandle> _callback; @@ -37,6 +38,33 @@ namespace YooAsset } } + /// <summary> + /// 等待异步执行完毕 + /// </summary> + public void WaitForAsyncComplete() + { + if (IsValidWithWarning == false) + return; + Provider.WaitForAsyncComplete(); + } + + /// <summary> + /// 释放资源句柄 + /// </summary> + public void Release() + { + this.ReleaseInternal(); + } + + /// <summary> + /// 释放资源句柄 + /// </summary> + public void Dispose() + { + this.ReleaseInternal(); + } + + /// <summary> /// 资源对象 /// </summary> @@ -61,25 +89,6 @@ namespace YooAsset return Provider.AssetObject as TAsset; } - /// <summary> - /// 等待异步执行完毕 - /// </summary> - public void WaitForAsyncComplete() - { - if (IsValidWithWarning == false) - return; - Provider.WaitForAsyncComplete(); - } - - /// <summary> - /// 释放资源句柄 - /// </summary> - public void Release() - { - this.ReleaseInternal(); - } - - /// <summary> /// 同步初始化游戏对象 /// </summary> diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs index b08a44c..6c8f081 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs @@ -3,20 +3,8 @@ using System.Collections; namespace YooAsset { - public abstract class OperationHandleBase : IEnumerator, IDisposable + public abstract class OperationHandleBase : IEnumerator { - private bool _isDisposed; - public void Dispose() - { - if (_isDisposed) - { - return; - } - - _isDisposed = true; - ReleaseInternal(); - } - private readonly AssetInfo _assetInfo; internal ProviderBase Provider { private set; get; } @@ -27,7 +15,6 @@ namespace YooAsset } internal abstract void InvokeCallback(); - /// <summary> /// 获取资源信息 /// </summary> diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/RawFileOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/RawFileOperationHandle.cs index 08d244c..4f41857 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/RawFileOperationHandle.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/RawFileOperationHandle.cs @@ -1,9 +1,10 @@ -using System.IO; +using System; +using System.IO; using System.Text; namespace YooAsset { - public class RawFileOperationHandle : OperationHandleBase + public class RawFileOperationHandle : OperationHandleBase, IDisposable { private System.Action<RawFileOperationHandle> _callback; @@ -54,7 +55,15 @@ namespace YooAsset { this.ReleaseInternal(); } - + + /// <summary> + /// 释放资源句柄 + /// </summary> + public void Dispose() + { + this.ReleaseInternal(); + } + /// <summary> /// 获取原生文件的二进制数据 diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/SubAssetsOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/SubAssetsOperationHandle.cs index 59ee557..9c050a4 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/SubAssetsOperationHandle.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/SubAssetsOperationHandle.cs @@ -1,8 +1,9 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace YooAsset { - public sealed class SubAssetsOperationHandle : OperationHandleBase + public sealed class SubAssetsOperationHandle : OperationHandleBase, IDisposable { private System.Action<SubAssetsOperationHandle> _callback; @@ -36,19 +37,6 @@ namespace YooAsset } } - /// <summary> - /// 子资源对象集合 - /// </summary> - public UnityEngine.Object[] AllAssetObjects - { - get - { - if (IsValidWithWarning == false) - return null; - return Provider.AllAssetObjects; - } - } - /// <summary> /// 等待异步执行完毕 /// </summary> @@ -67,6 +55,27 @@ namespace YooAsset this.ReleaseInternal(); } + /// <summary> + /// 释放资源句柄 + /// </summary> + public void Dispose() + { + this.ReleaseInternal(); + } + + + /// <summary> + /// 子资源对象集合 + /// </summary> + public UnityEngine.Object[] AllAssetObjects + { + get + { + if (IsValidWithWarning == false) + return null; + return Provider.AllAssetObjects; + } + } /// <summary> /// 获取子资源对象