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.
 
 
 

130 satır
3.3 KiB

  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. namespace SUISS.Scheduling
  6. {
  7. public class CoYield : IYieldStatement
  8. {
  9. protected CoYield()
  10. {
  11. this._type = CoYield.YieldType.NullYield;
  12. }
  13. protected CoYield(CoYield.YieldType type, object yieldable)
  14. {
  15. this._type = type;
  16. this._yieldable = yieldable;
  17. }
  18. public static IYieldStatement On(UnityWebRequest webRequest)
  19. {
  20. return new CoYield(CoYield.YieldType.WWW, webRequest);
  21. }
  22. public static IYieldStatement On(double suissYield)
  23. {
  24. return new CoYield(CoYield.YieldType.SUISSYield, suissYield);
  25. }
  26. public static IYieldStatement On(float waitSeconds)
  27. {
  28. return new CoYield(CoYield.YieldType.UnityYield, new WaitForSeconds(waitSeconds));
  29. }
  30. public static IYieldStatement On(YieldInstruction unityYield)
  31. {
  32. return new CoYield(CoYield.YieldType.UnityYield, unityYield);
  33. }
  34. public static IYieldStatement On(IEnumerator busyEnumerator)
  35. {
  36. return new CoYield(CoYield.YieldType.Enumerator, busyEnumerator);
  37. }
  38. public static IYieldStatement NextFrame()
  39. {
  40. return new CoYield();
  41. }
  42. public object UnityYieldable(MonoBehaviour runner)
  43. {
  44. switch (this._type)
  45. {
  46. case CoYield.YieldType.Enumerator:
  47. {
  48. if (runner == null)
  49. {
  50. UnityEngine.Debug.LogError("Error! Cannot use busy IEnumerator a unity yield statement!");
  51. throw new Exception("Error! Cannot use busy IEnumerator a unity yield statement!");
  52. }
  53. IEnumerator enumerator = this._yieldable as IEnumerator;
  54. if (enumerator == null)
  55. {
  56. UnityEngine.Debug.LogError("Busy IEnumerator was null. This is unexpected!");
  57. throw new Exception("Busy IEnumerator was null. This is unexpected!");
  58. }
  59. return runner.StartCoroutine(enumerator);
  60. }
  61. case CoYield.YieldType.WWW:
  62. case CoYield.YieldType.UnityYield:
  63. if (this._yieldable == null)
  64. {
  65. UnityEngine.Debug.LogError("A unity yield object was null. This is unexpected!");
  66. throw new Exception("A unity yield object was null. This is unexpected!");
  67. }
  68. return this._yieldable;
  69. case CoYield.YieldType.SUISSYield:
  70. UnityEngine.Debug.LogWarning("A SUISS yield instruction is being passed to the Unity Scheduler. You probably don't want this!");
  71. return null;
  72. default:
  73. return null;
  74. }
  75. }
  76. public object UnityYieldable()
  77. {
  78. return this.UnityYieldable(null);
  79. }
  80. public object SUISSYieldable()
  81. {
  82. switch (this._type)
  83. {
  84. case CoYield.YieldType.Enumerator:
  85. if (!(this._yieldable is IEnumerator))
  86. {
  87. UnityEngine.Debug.LogError("Busy IEnumerator was null. This is unexpected!");
  88. throw new Exception("Busy IEnumerator was null. This is unexpected!");
  89. }
  90. return this._yieldable;
  91. case CoYield.YieldType.WWW:
  92. case CoYield.YieldType.UnityYield:
  93. case CoYield.YieldType.SUISSYield:
  94. if (this._yieldable == null)
  95. {
  96. UnityEngine.Debug.LogError("A yield object was null. This is unexpected!");
  97. throw new Exception("A yield object was null. This is unexpected!");
  98. }
  99. return this._yieldable;
  100. default:
  101. return null;
  102. }
  103. }
  104. private object _yieldable;
  105. private CoYield.YieldType _type;
  106. protected enum YieldType
  107. {
  108. Enumerator,
  109. WWW,
  110. UnityYield,
  111. SUISSYield,
  112. NullYield
  113. }
  114. }
  115. }