diff --git a/GFramework.Core/coroutine/instructions/WaitForAllCoroutines.cs b/GFramework.Core/coroutine/instructions/WaitForAllCoroutines.cs index 54d3e2f..c0a33a8 100644 --- a/GFramework.Core/coroutine/instructions/WaitForAllCoroutines.cs +++ b/GFramework.Core/coroutine/instructions/WaitForAllCoroutines.cs @@ -5,23 +5,30 @@ namespace GFramework.Core.coroutine.instructions; /// /// 等待所有协程完成的等待指令 /// -public sealed class WaitForAllCoroutines( - CoroutineScheduler scheduler, - IReadOnlyList handles) - : IYieldInstruction +public sealed class WaitForAllCoroutines : IYieldInstruction { - private readonly IReadOnlyList _handles = - handles ?? throw new ArgumentNullException(nameof(handles)); + private readonly IReadOnlyList _handles; + private readonly CoroutineScheduler _scheduler; + private bool _isDone; - private readonly CoroutineScheduler _scheduler = scheduler ?? throw new ArgumentNullException(nameof(scheduler)); + public WaitForAllCoroutines( + CoroutineScheduler scheduler, + IReadOnlyList handles) + { + _scheduler = scheduler ?? throw new ArgumentNullException(nameof(scheduler)); + _handles = handles ?? throw new ArgumentNullException(nameof(handles)); + + // 空列表直接完成 + _isDone = _handles.Count == 0; + } public void Update(double deltaTime) { - // 不需要做任何事 + if (_isDone) return; + + // 检查所有协程是否都已完成 + _isDone = _handles.All(handle => !_scheduler.IsCoroutineAlive(handle)); } - public bool IsDone - { - get { return _handles.All(handle => !_scheduler.IsCoroutineAlive(handle)); } - } + public bool IsDone => _isDone; } \ No newline at end of file