Class CoroutineUtilities
Contains many useful utility functions when dealing with coroutines
Namespace: WeaverCore.Utilities
Assembly: WeaverCore.dll
Syntax
public static class CoroutineUtilities
Methods
| Edit this page View SourceRunAfter(float, Action)
Runs a function after a specified amount of time
Declaration
public static IEnumerator RunAfter(float time, Action action)
Parameters
Type | Name | Description |
---|---|---|
float | time | The time to wait |
Action | action | The function to run |
Returns
Type | Description |
---|---|
IEnumerator |
RunAfter(float, Func<IEnumerator>)
Runs a function after a specified amount of time
Declaration
public static IEnumerator RunAfter(float time, Func<IEnumerator> action)
Parameters
Type | Name | Description |
---|---|---|
float | time | The time to wait |
Func<IEnumerator> | action | The function to run |
Returns
Type | Description |
---|---|
IEnumerator |
RunCoroutineWhile<T>(T, IEnumerator, Func<bool>)
Will allow a coroutine to run while the predicate is true. If the predicate returns false, the coroutine will end
Declaration
public static Coroutine RunCoroutineWhile<T>(this T component, IEnumerator routine, Func<bool> predicate) where T : MonoBehaviour
Parameters
Type | Name | Description |
---|---|---|
T | component | The component to start the coroutine under |
IEnumerator | routine | The function to be executed by the coroutine |
Func<bool> | predicate | The predicate function that either returns true or false to control whether the coroutine should be executing or not |
Returns
Type | Description |
---|---|
Coroutine | The started coroutine |
Type Parameters
Name | Description |
---|---|
T | The component type |
RunForPeriod(float, Action)
Will continously run the action function for a set period of time.
Declaration
public static IEnumerator RunForPeriod(float time, Action action)
Parameters
Type | Name | Description |
---|---|---|
float | time | The amount of time the action function should be called for |
Action | action | The action function to be continously called each frame for a set period of time. |
Returns
Type | Description |
---|---|
IEnumerator |
RunForPeriod(float, Action<float>)
Will continously run the action function for a set period of time.
Declaration
public static IEnumerator RunForPeriod(float time, Action<float> action)
Parameters
Type | Name | Description |
---|---|---|
float | time | The amount of time the action function should be called for |
Action<float> | action | The action function to be continously called each frame for a set period of time. This version of the allows the action to take in the amount of elapsed time as a parameter |
Returns
Type | Description |
---|---|
IEnumerator |
RunForPeriod(float, Func<bool>)
Will continously run the action function for a set period of time. The loop can be stopped prematurely by returning false from the action function
Declaration
public static IEnumerator RunForPeriod(float time, Func<bool> action)
Parameters
Type | Name | Description |
---|---|---|
float | time | The amount of time the action function should be called for |
Func<bool> | action | The action function to be continously called each frame for a set period of time. If the action returns false at any time, the loop will stop prematurely |
Returns
Type | Description |
---|---|
IEnumerator |
RunForPeriod(float, Func<float, bool>)
/// Will continously run the action function for a set period of time. The loop can be stopped prematurely by returning false from the action function
Declaration
public static IEnumerator RunForPeriod(float time, Func<float, bool> action)
Parameters
Type | Name | Description |
---|---|---|
float | time | The amount of time the action function should be called for |
Func<float, bool> | action | The action function to be continously called each frame for a set period of time. This version of the allows the action to take in the amount of elapsed time as a parameter. If the action returns false at any time, the loop will stop prematurely |
Returns
Type | Description |
---|---|
IEnumerator |
RunWhile(IEnumerator, Func<bool>)
Runs an IEnumerator while the predicate is true. If the predicate returns false, then the IEnumerator will end
Declaration
public static IEnumerator RunWhile(IEnumerator routine, Func<bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
IEnumerator | routine | The IEnumerator to execute |
Func<bool> | predicate |
|
Returns
Type | Description |
---|---|
IEnumerator | The IEnumerator that executes the routine |
WaitForTimeOrPredicate(float, Func<bool>)
Waits until either the predicate returns true or if the time has elapsed
Declaration
public static IEnumerator WaitForTimeOrPredicate(float time, Func<bool> predicate)
Parameters
Type | Name | Description |
---|---|---|
float | time | The time to wait |
Func<bool> | predicate | The predicate to check |
Returns
Type | Description |
---|---|
IEnumerator |