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 调试信息