Skip to content

Commit 252d4ed

Browse files
committed
chore: GlobalCoroutine.IsDestroyed check added for the Coroutine utility
1 parent 15b85d3 commit 252d4ed

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Runtime/Async/Coroutine/CoroutineUtility.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public static Coroutine Start(IEnumerator routine)
4040
/// <param name="routine">The <see cref="IEnumerator"/> routine you would like to stop.</param>
4141
public static void Stop(IEnumerator routine)
4242
{
43+
if(GlobalCoroutine.IsDestroyed)
44+
return;
45+
4346
GlobalCoroutine.Instance.StopCoroutine(routine);
4447
}
4548

@@ -50,6 +53,9 @@ public static void Stop(IEnumerator routine)
5053
/// <param name="routine">The <see cref="Coroutine"/> to stop the manually created <see cref="Coroutine"/></param>
5154
public static void Stop(Coroutine routine)
5255
{
56+
if(GlobalCoroutine.IsDestroyed)
57+
return;
58+
5359
GlobalCoroutine.Instance.StopCoroutine(routine);
5460
}
5561

@@ -60,6 +66,9 @@ public static void Stop(Coroutine routine)
6066
/// <param name="action">The callback action.</param>
6167
public static void WaitForEndOfFrame(Action action)
6268
{
69+
if(GlobalCoroutine.IsDestroyed)
70+
return;
71+
6372
GlobalCoroutine.Instance.StartInstruction(new WaitForEndOfFrame(), action);
6473
}
6574

@@ -70,6 +79,9 @@ public static void WaitForEndOfFrame(Action action)
7079
/// </summary>
7180
public static void WaitForFixedUpdate(Action action)
7281
{
82+
if(GlobalCoroutine.IsDestroyed)
83+
return;
84+
7385
GlobalCoroutine.Instance.StartInstruction(new WaitForFixedUpdate(), action);
7486
}
7587

@@ -81,6 +93,9 @@ public static void WaitForFixedUpdate(Action action)
8193
/// </summary>
8294
public static void WaitForSeconds(float seconds, Action action)
8395
{
96+
if(GlobalCoroutine.IsDestroyed)
97+
return;
98+
8499
GlobalCoroutine.Instance.StartInstruction(new WaitForSeconds(seconds), action);
85100
}
86101

@@ -92,6 +107,9 @@ public static void WaitForSeconds(float seconds, Action action)
92107
/// <param name="action">The callback action.</param>
93108
public static void WaitForSecondsRealtime(float seconds, Action action)
94109
{
110+
if(GlobalCoroutine.IsDestroyed)
111+
return;
112+
95113
GlobalCoroutine.Instance.StartInstruction(new WaitForSecondsRealtime(seconds), action);
96114
}
97115

@@ -103,6 +121,9 @@ public static void WaitForSecondsRealtime(float seconds, Action action)
103121
/// <param name="action">The callback action.</param>
104122
public static void WaitForSecondsWithRandomInterval(float min, float max, Action action)
105123
{
124+
if(GlobalCoroutine.IsDestroyed)
125+
return;
126+
106127
var delay = UnityEngine.Random.Range(min, max);
107128
WaitForSeconds(delay, action);
108129
}

0 commit comments

Comments
 (0)