From 9e19f776af03bf79f29796debaad387a872644b6 Mon Sep 17 00:00:00 2001 From: hevinci Date: Thu, 24 Mar 2022 00:20:29 +0800 Subject: [PATCH] Update OperationSystem --- .../OperationSystem/OperationSystem.cs | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) 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