CoroutineHelper.cs 675 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections;
  2. using UnityEngine;
  3. namespace DunGen
  4. {
  5. public sealed class CoroutineHelper : MonoBehaviour
  6. {
  7. private static CoroutineHelper instance;
  8. private static CoroutineHelper Instance
  9. {
  10. get
  11. {
  12. if (instance == null)
  13. {
  14. var obj = new GameObject("DunGen Coroutine Helper");
  15. obj.hideFlags = HideFlags.HideInHierarchy;
  16. instance = obj.AddComponent<CoroutineHelper>();
  17. }
  18. return instance;
  19. }
  20. }
  21. public static Coroutine Start(IEnumerator routine)
  22. {
  23. return Instance.StartCoroutine(routine);
  24. }
  25. public static void StopAll()
  26. {
  27. Instance.StopAllCoroutines();
  28. }
  29. }
  30. }