Created
February 18, 2024 16:43
-
-
Save corvus-mt/595ecbe367b68f113d900f19a2d4584b to your computer and use it in GitHub Desktop.
WaitForCoroutines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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