From a85e49c22acdd2076f6df03fe296a0c034d977cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Thu, 28 Aug 2025 22:07:00 +0800 Subject: [PATCH] fix #625 --- .../OperationSystem/OperationSystem.cs | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs b/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs index 7528a787..06822afe 100644 --- a/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs +++ b/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs @@ -1,4 +1,5 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using System.Diagnostics; @@ -16,6 +17,8 @@ namespace YooAsset private static readonly List _operations = new List(1000); private static readonly List _newList = new List(1000); + private static Action _startCallback = null; + private static Action _finishCallback = null; // 计时器相关 private static Stopwatch _watch; @@ -58,7 +61,12 @@ namespace YooAsset { var operation = _operations[i]; if (operation.IsFinish) + { _operations.RemoveAt(i); + + if (_finishCallback != null) + _finishCallback.Invoke(operation.PackageName, operation); + } } // 添加新增的异步操作 @@ -105,6 +113,8 @@ namespace YooAsset { _operations.Clear(); _newList.Clear(); + _startCallback = null; + _finishCallback = null; _watch = null; _frameTime = 0; MaxTimeSlice = long.MaxValue; @@ -142,6 +152,25 @@ namespace YooAsset _newList.Add(operation); operation.SetPackageName(packageName); operation.StartOperation(); + + if (_startCallback != null) + _startCallback.Invoke(packageName, operation); + } + + /// + /// 监听任务开始 + /// + public static void RegisterStartCallback(Action callback) + { + _startCallback = callback; + } + + /// + /// 监听任务结束 + /// + public static void RegisterFinishCallback(Action callback) + { + _finishCallback = callback; } #region 调试信息