-
Notifications
You must be signed in to change notification settings - Fork 0
WaitFor Utility Class
Andrzej Kebab edited this page Feb 4, 2024
·
1 revision
The WaitFor class in the UtilityLibrary.Unity.Runtime namespace provides cached instances of Unity's WaitForFixedUpdate, WaitForEndOfFrame, WaitForSeconds, and WaitForSecondsRealtime. This utility class helps reduce memory allocation by reusing instances for commonly used wait periods.
-
ForFixedUpdate: A cached instance of
WaitForFixedUpdate. -
ForEndOfFrame: A cached instance of
WaitForEndOfFrame. -
ForSeconds: A cached instance of
WaitForSecondsCache, allowing access toWaitForSecondswith cached durations. -
ForSecondsRealtime: A cached instance of
WaitForSecondsRealtimeCache, allowing access toWaitForSecondsRealtimewith cached durations.
-
Properties
-
Item[float time]: Gets a cached instance of
WaitForSecondswith the specified duration.
-
Item[float time]: Gets a cached instance of
-
Properties
-
Item[float time]: Gets a cached instance of
WaitForSecondsRealtimewith the specified duration.
-
Item[float time]: Gets a cached instance of
// Use cached instances of WaitForSeconds and WaitForSecondsRealtime
IEnumerator Start()
{
Debug.Log("Start Coroutine");
yield return WaitFor.ForSeconds[2.0f];
Debug.Log("After 2 seconds");
yield return WaitFor.ForSecondsRealtime[3.0f];
Debug.Log("After 3 seconds in real time");
yield return WaitFor.ForFixedUpdate;
Debug.Log("After the next FixedUpdate");
yield return WaitFor.ForEndOfFrame;
Debug.Log("After the end of the frame");
}This utility class simplifies coroutine waiting in Unity by providing cached instances of commonly used WaitFor types, reducing memory allocation and enhancing performance.