mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-18 14:00:18 +00:00
69 lines
1.2 KiB
C#
69 lines
1.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace YooAsset
|
|
{
|
|
public abstract class AsyncOperationBase : IEnumerator
|
|
{
|
|
// 用户请求的回调
|
|
private Action<AsyncOperationBase> _callback;
|
|
|
|
/// <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>
|
|
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
|
|
}
|
|
} |