Skip to content

Commit 12023eb

Browse files
committed
Added InvokeCoroutine and InvokeDelayed helper methods.
1 parent ef782a9 commit 12023eb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Runtime/DevConsole.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#endif
88

99
using System;
10+
using System.Collections;
11+
using System.Collections.Generic;
1012
using UnityEngine;
1113

1214
using InputKey =
@@ -305,6 +307,31 @@ public static void ClearConsole()
305307
_console.ClearConsole();
306308
}
307309

310+
/// <summary>
311+
/// Invoke an enumerator as a Unity coroutine. Useful for commands that may not have a reference to a MonoBehaviour.
312+
/// </summary>
313+
/// <param name="enumerator"></param>
314+
public static void InvokeCoroutine(IEnumerator enumerator)
315+
{
316+
_console.StartCoroutine(enumerator);
317+
}
318+
319+
/// <summary>
320+
/// Invoke an action after a specified time has passed. Useful for commands that may not have a reference to a MonoBehaviour.
321+
/// </summary>
322+
/// <param name="action"></param>
323+
/// <param name="delay"></param>
324+
public static void InvokeDelayed(Action action, float delay)
325+
{
326+
IEnumerator Invoke()
327+
{
328+
yield return new WaitForSeconds(delay);
329+
action?.Invoke();
330+
}
331+
332+
_console.StartCoroutine(Invoke());
333+
}
334+
308335
#region Invoke events
309336

310337
internal static void InvokeOnConsoleEnabled()

0 commit comments

Comments
 (0)