diff --git a/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs b/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs index 5682539..e06a0c0 100644 --- a/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs +++ b/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using System.Diagnostics; namespace YooAsset { @@ -7,16 +8,33 @@ namespace YooAsset { private static readonly List _operations = new List(100); - public static void ProcessOperaiton(AsyncOperationBase operationBase) + // 计时器相关 + private static Stopwatch _watch; + private static long _maxTimeSlice; + private static long _frameTime; + + + /// + /// 初始化异步操作系统 + /// + public static void Initialize(long maxTimeSlice) { - _operations.Add(operationBase); - operationBase.Start(); + _maxTimeSlice = maxTimeSlice; + _watch = Stopwatch.StartNew(); } + /// + /// 更新异步操作系统 + /// public static void Update() { + _frameTime = _watch.ElapsedMilliseconds; + for (int i = _operations.Count - 1; i >= 0; i--) { + if (_watch.ElapsedMilliseconds - _frameTime >= _maxTimeSlice) + return; + _operations[i].Update(); if (_operations[i].IsDone) { @@ -25,5 +43,14 @@ namespace YooAsset } } } + + /// + /// 开始处理异步操作类 + /// + public static void ProcessOperaiton(AsyncOperationBase operationBase) + { + _operations.Add(operationBase); + operationBase.Start(); + } } } \ No newline at end of file