Initial commit
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e928a1c08d679ad44bcb435678667fd7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public enum EOperationStatus
|
||||
{
|
||||
None,
|
||||
Succeed,
|
||||
Failed
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b0b0ed13c7433847a91c0ffd8306125
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class OperationUpdater
|
||||
{
|
||||
private static readonly List<AsyncOperationBase> _operations = new List<AsyncOperationBase>(100);
|
||||
|
||||
public static void ProcessOperaiton(AsyncOperationBase operationBase)
|
||||
{
|
||||
_operations.Add(operationBase);
|
||||
operationBase.Start();
|
||||
}
|
||||
|
||||
public static void Update()
|
||||
{
|
||||
for (int i = _operations.Count - 1; i >= 0; i--)
|
||||
{
|
||||
_operations[i].Update();
|
||||
if (_operations[i].IsDone)
|
||||
{
|
||||
_operations[i].Finish();
|
||||
_operations.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b20b2efe14ab7e8498edb9819d24a172
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user