mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-29 12:41:00 +00:00
Update OperationSystem
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
@@ -7,16 +8,33 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
private static readonly List<AsyncOperationBase> _operations = new List<AsyncOperationBase>(100);
|
private static readonly List<AsyncOperationBase> _operations = new List<AsyncOperationBase>(100);
|
||||||
|
|
||||||
public static void ProcessOperaiton(AsyncOperationBase operationBase)
|
// 计时器相关
|
||||||
|
private static Stopwatch _watch;
|
||||||
|
private static long _maxTimeSlice;
|
||||||
|
private static long _frameTime;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 初始化异步操作系统
|
||||||
|
/// </summary>
|
||||||
|
public static void Initialize(long maxTimeSlice)
|
||||||
{
|
{
|
||||||
_operations.Add(operationBase);
|
_maxTimeSlice = maxTimeSlice;
|
||||||
operationBase.Start();
|
_watch = Stopwatch.StartNew();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 更新异步操作系统
|
||||||
|
/// </summary>
|
||||||
public static void Update()
|
public static void Update()
|
||||||
{
|
{
|
||||||
|
_frameTime = _watch.ElapsedMilliseconds;
|
||||||
|
|
||||||
for (int i = _operations.Count - 1; i >= 0; i--)
|
for (int i = _operations.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
|
if (_watch.ElapsedMilliseconds - _frameTime >= _maxTimeSlice)
|
||||||
|
return;
|
||||||
|
|
||||||
_operations[i].Update();
|
_operations[i].Update();
|
||||||
if (_operations[i].IsDone)
|
if (_operations[i].IsDone)
|
||||||
{
|
{
|
||||||
@@ -25,5 +43,14 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 开始处理异步操作类
|
||||||
|
/// </summary>
|
||||||
|
public static void ProcessOperaiton(AsyncOperationBase operationBase)
|
||||||
|
{
|
||||||
|
_operations.Add(operationBase);
|
||||||
|
operationBase.Start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user