mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-25 02:00:16 +00:00
Update YooAsset
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public abstract class AsyncOperationBase : IEnumerator
|
||||
{
|
||||
/// <summary>
|
||||
/// 状态
|
||||
/// </summary>
|
||||
public EOperationStatus Status { get; protected set; } = EOperationStatus.None;
|
||||
|
||||
/// <summary>
|
||||
/// 错误信息
|
||||
/// </summary>
|
||||
public string Error { get; protected set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 是否已经完成
|
||||
/// </summary>
|
||||
public bool IsDone
|
||||
{
|
||||
get
|
||||
{
|
||||
return Status == EOperationStatus.Failed || Status == EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户请求的回调
|
||||
/// </summary>
|
||||
private Action<AsyncOperationBase> _callback;
|
||||
|
||||
/// <summary>
|
||||
/// 完成事件
|
||||
/// </summary>
|
||||
public event Action<AsyncOperationBase> Completed
|
||||
{
|
||||
add
|
||||
{
|
||||
if (IsDone)
|
||||
value.Invoke(this);
|
||||
else
|
||||
_callback += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_callback -= value;
|
||||
}
|
||||
}
|
||||
|
||||
internal abstract void Start();
|
||||
internal abstract void Update();
|
||||
internal void Finish()
|
||||
{
|
||||
_callback?.Invoke(this);
|
||||
}
|
||||
|
||||
#region 异步相关
|
||||
public bool MoveNext()
|
||||
{
|
||||
return !IsDone;
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
}
|
||||
public object Current => null;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user