25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

124 satır
2.7 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace SUISS.Scheduling
  6. {
  7. [Obsolete("If you need the SUISS.Scheduling.Scheduler for an _ingame_ courtine use Scheduler.Instance.")]
  8. public class SUISSScheduler : IScheduler
  9. {
  10. public SUISSScheduler(Scheduler scheduler)
  11. {
  12. this._scheduler = scheduler;
  13. }
  14. public SUISSScheduler(Func<Scheduler> schedulerGetter)
  15. {
  16. this._schedulerGetter = schedulerGetter;
  17. }
  18. public ICoroutine StartCoroutine(IEnumerator<IYieldStatement> routine)
  19. {
  20. if (this._scheduler == null)
  21. {
  22. if (this._schedulerGetter == null)
  23. {
  24. return null;
  25. }
  26. this._scheduler = this._schedulerGetter();
  27. if (this._scheduler == null)
  28. {
  29. UnityEngine.Debug.LogWarning("The SUISS scheduler backing this scheduler is null!");
  30. return null;
  31. }
  32. }
  33. return new SUISSScheduler.Coroutine(routine, this._scheduler);
  34. }
  35. private Scheduler _scheduler;
  36. private Func<Scheduler> _schedulerGetter;
  37. private class Coroutine : ICoroutine, IYieldStatement
  38. {
  39. public Coroutine(IEnumerator<IYieldStatement> routine, Scheduler scheduler)
  40. {
  41. this._scheduler = scheduler;
  42. if (this._scheduler != null)
  43. {
  44. this._isRunning = true;
  45. this._routine = this.Routine(routine);
  46. this._scheduler.StartRoutine(this._routine);
  47. }
  48. }
  49. public void Stop()
  50. {
  51. if (this._isRunning && this._scheduler != null)
  52. {
  53. this._scheduler.StopRoutine(this._routine);
  54. this._isRunning = false;
  55. }
  56. }
  57. public bool IsRunning
  58. {
  59. get
  60. {
  61. return this._isRunning;
  62. }
  63. }
  64. public object UnityYieldable()
  65. {
  66. UnityEngine.Debug.LogWarning("Coroutines started using the SUISS scheduler should not be mixed with the UnityScheduler.");
  67. return null;
  68. }
  69. public object UnityYieldable(MonoBehaviour runner)
  70. {
  71. UnityEngine.Debug.LogWarning("Coroutines started using the SUISS scheduler should not be mixed with the UnityScheduler.");
  72. return null;
  73. }
  74. public object SUISSYieldable()
  75. {
  76. return this.BusyWait();
  77. }
  78. private IEnumerator BusyWait()
  79. {
  80. while (this._isRunning)
  81. {
  82. yield return null;
  83. }
  84. yield break;
  85. }
  86. private IEnumerator Routine(IEnumerator<IYieldStatement> routine)
  87. {
  88. while (routine.MoveNext())
  89. {
  90. if (routine.Current != null)
  91. {
  92. yield return routine.Current.SUISSYieldable();
  93. }
  94. else
  95. {
  96. yield return null;
  97. }
  98. }
  99. this._isRunning = false;
  100. yield break;
  101. }
  102. private IEnumerator _routine;
  103. private Scheduler _scheduler;
  104. private bool _isRunning;
  105. }
  106. }
  107. }