Update asset system

pull/62/head
hevinci 2022-12-03 19:13:11 +08:00
parent 4abec5a389
commit 6038e7acd6
4 changed files with 67 additions and 53 deletions

View File

@ -1,9 +1,10 @@
using UnityEngine; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
public sealed class AssetOperationHandle : OperationHandleBase public sealed class AssetOperationHandle : OperationHandleBase, IDisposable
{ {
private System.Action<AssetOperationHandle> _callback; 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>
/// 资源对象 /// 资源对象
/// </summary> /// </summary>
@ -61,25 +89,6 @@ namespace YooAsset
return Provider.AssetObject as TAsset; 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>
/// 同步初始化游戏对象 /// 同步初始化游戏对象
/// </summary> /// </summary>

View File

@ -3,20 +3,8 @@ using System.Collections;
namespace YooAsset 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; private readonly AssetInfo _assetInfo;
internal ProviderBase Provider { private set; get; } internal ProviderBase Provider { private set; get; }
@ -27,7 +15,6 @@ namespace YooAsset
} }
internal abstract void InvokeCallback(); internal abstract void InvokeCallback();
/// <summary> /// <summary>
/// 获取资源信息 /// 获取资源信息
/// </summary> /// </summary>

View File

@ -1,9 +1,10 @@
using System.IO; using System;
using System.IO;
using System.Text; using System.Text;
namespace YooAsset namespace YooAsset
{ {
public class RawFileOperationHandle : OperationHandleBase public class RawFileOperationHandle : OperationHandleBase, IDisposable
{ {
private System.Action<RawFileOperationHandle> _callback; private System.Action<RawFileOperationHandle> _callback;
@ -55,6 +56,14 @@ namespace YooAsset
this.ReleaseInternal(); this.ReleaseInternal();
} }
/// <summary>
/// 释放资源句柄
/// </summary>
public void Dispose()
{
this.ReleaseInternal();
}
/// <summary> /// <summary>
/// 获取原生文件的二进制数据 /// 获取原生文件的二进制数据

View File

@ -1,8 +1,9 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
public sealed class SubAssetsOperationHandle : OperationHandleBase public sealed class SubAssetsOperationHandle : OperationHandleBase, IDisposable
{ {
private System.Action<SubAssetsOperationHandle> _callback; 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>
/// 等待异步执行完毕 /// 等待异步执行完毕
/// </summary> /// </summary>
@ -67,6 +55,27 @@ namespace YooAsset
this.ReleaseInternal(); 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> /// <summary>
/// 获取子资源对象 /// 获取子资源对象