mirror of https://github.com/tuyoogame/YooAsset
fix #96
parent
1aaf569396
commit
dcdf41b7c2
|
@ -77,9 +77,9 @@ namespace YooAsset
|
||||||
internal void SetFinish()
|
internal void SetFinish()
|
||||||
{
|
{
|
||||||
Progress = 1f;
|
Progress = 1f;
|
||||||
_callback?.Invoke(this);
|
|
||||||
if (_taskCompletionSource != null)
|
if (_taskCompletionSource != null)
|
||||||
_taskCompletionSource.TrySetResult(null);
|
_taskCompletionSource.TrySetResult(null);
|
||||||
|
_callback?.Invoke(this);
|
||||||
}
|
}
|
||||||
internal void SetStart()
|
internal void SetStart()
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,8 +7,7 @@ namespace YooAsset
|
||||||
internal class OperationSystem
|
internal class OperationSystem
|
||||||
{
|
{
|
||||||
private static readonly List<AsyncOperationBase> _operations = new List<AsyncOperationBase>(100);
|
private static readonly List<AsyncOperationBase> _operations = new List<AsyncOperationBase>(100);
|
||||||
private static readonly List<AsyncOperationBase> _addList = new List<AsyncOperationBase>(100);
|
private static readonly List<AsyncOperationBase> _newList = new List<AsyncOperationBase>(100);
|
||||||
private static readonly List<AsyncOperationBase> _removeList = new List<AsyncOperationBase>(100);
|
|
||||||
|
|
||||||
// 计时器相关
|
// 计时器相关
|
||||||
private static Stopwatch _watch;
|
private static Stopwatch _watch;
|
||||||
|
@ -47,39 +46,26 @@ namespace YooAsset
|
||||||
_frameTime = _watch.ElapsedMilliseconds;
|
_frameTime = _watch.ElapsedMilliseconds;
|
||||||
|
|
||||||
// 添加新的异步操作
|
// 添加新的异步操作
|
||||||
if (_addList.Count > 0)
|
if (_newList.Count > 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _addList.Count; i++)
|
_operations.AddRange(_newList);
|
||||||
{
|
_newList.Clear();
|
||||||
var operation = _addList[i];
|
|
||||||
_operations.Add(operation);
|
|
||||||
}
|
|
||||||
_addList.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新所有的异步操作
|
// 更新所有的异步操作
|
||||||
foreach (var operation in _operations)
|
for (int i = _operations.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (IsBusy)
|
if (IsBusy)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
var operation = _operations[i];
|
||||||
operation.Update();
|
operation.Update();
|
||||||
if (operation.IsDone)
|
if (operation.IsDone)
|
||||||
{
|
{
|
||||||
_removeList.Add(operation);
|
_operations.RemoveAt(i);
|
||||||
operation.SetFinish();
|
operation.SetFinish(); //注意:如果业务端发生异常,保证异步操作提前移除。
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 移除已经完成的异步操作
|
|
||||||
if (_removeList.Count > 0)
|
|
||||||
{
|
|
||||||
foreach (var operation in _removeList)
|
|
||||||
{
|
|
||||||
_operations.Remove(operation);
|
|
||||||
}
|
|
||||||
_removeList.Clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -88,8 +74,7 @@ namespace YooAsset
|
||||||
public static void DestroyAll()
|
public static void DestroyAll()
|
||||||
{
|
{
|
||||||
_operations.Clear();
|
_operations.Clear();
|
||||||
_addList.Clear();
|
_newList.Clear();
|
||||||
_removeList.Clear();
|
|
||||||
_watch = null;
|
_watch = null;
|
||||||
_frameTime = 0;
|
_frameTime = 0;
|
||||||
MaxTimeSlice = long.MaxValue;
|
MaxTimeSlice = long.MaxValue;
|
||||||
|
@ -100,7 +85,7 @@ namespace YooAsset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void StartOperation(AsyncOperationBase operation)
|
public static void StartOperation(AsyncOperationBase operation)
|
||||||
{
|
{
|
||||||
_addList.Add(operation);
|
_newList.Add(operation);
|
||||||
operation.SetStart();
|
operation.SetStart();
|
||||||
operation.Start();
|
operation.Start();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue