Skip to content

Instantly share code, notes, and snippets.

@corvus-mt
Created February 18, 2024 16:43
Show Gist options
  • Save corvus-mt/595ecbe367b68f113d900f19a2d4584b to your computer and use it in GitHub Desktop.
Save corvus-mt/595ecbe367b68f113d900f19a2d4584b to your computer and use it in GitHub Desktop.
WaitForCoroutines
using System.Collections;
using UnityEngine;
public class WaitForCoroutines : CustomYieldInstruction
{
public override bool keepWaiting => _remainCount > 0;
private int _remainCount;
public WaitForCoroutines(MonoBehaviour runner, params IEnumerator[] coroutines)
{
IEnumerator WaitingCoroutine(IEnumerator coroutine)
{
yield return coroutine;
_remainCount--;
}
_remainCount = coroutines.Length;
for (var i = 0; i < _remainCount; i++)
{
runner.StartCoroutine(WaitingCoroutine(coroutines[i]));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment