using System; using System.Runtime.CompilerServices; using System.Threading; namespace UnityAsync { public static partial class Await { static readonly AwaitInstructionAwaiter nextUpdate = new AwaitInstructionAwaiter(new WaitForFrames(1)); static readonly AwaitInstructionAwaiter nextLateUpdate = new AwaitInstructionAwaiter(new WaitForFrames(1), FrameScheduler.LateUpdate); static readonly AwaitInstructionAwaiter nextFixedUpdate = new AwaitInstructionAwaiter(new WaitForFrames(1), FrameScheduler.FixedUpdate); /// /// Quick access to Unity's . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SynchronizationContext UnitySyncContext() => AsyncManager.UnitySyncContext; /// /// Quick access to the background . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SynchronizationContext BackgroundSyncContext() => AsyncManager.BackgroundSyncContext; /// /// Convenience function to skip a single frame, equivalent to Unity's yield return null. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AwaitInstructionAwaiter NextUpdate() => nextUpdate; /// /// Convenience function to skip a number of frames, equivalent to multiple yield return nulls. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AwaitInstructionAwaiter Updates(int count) => new AwaitInstructionAwaiter(new WaitForFrames(count)); /// /// Convenience function to skip a single frame and continue in the LateUpdate loop. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AwaitInstructionAwaiter NextLateUpdate() => nextLateUpdate; /// /// Convenience function to skip multiple frames and continue in the LateUpdate loop. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AwaitInstructionAwaiter LateUpdates(int count) => new AwaitInstructionAwaiter(new WaitForFrames(count), FrameScheduler.LateUpdate); /// /// Convenience function to skip a single FixedUpdate frame and continue in the FixedUpdate loop. Equivalent to /// Unity's . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AwaitInstructionAwaiter NextFixedUpdate() => nextFixedUpdate; /// /// Convenience function to skip multiple FixedUpdate frames and continue in the FixedUpdate loop. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static AwaitInstructionAwaiter FixedUpdates(int count) => new AwaitInstructionAwaiter(new WaitForFrames(count), FrameScheduler.FixedUpdate); /// /// Convenience function to wait for a number of in-game seconds before continuing, equivalent to Unity's /// . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WaitForSeconds Seconds(float duration) => new WaitForSeconds(duration); /// /// Convenience function to wait for a number of unscaled seconds before continuing. Equivalent to Unity's /// . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WaitForSecondsRealtime SecondsRealtime(float duration) => new WaitForSecondsRealtime(duration); /// /// Convenience function to wait for a condition to return true. Equivalent to Unity's /// . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WaitUntil Until(Func condition) => new WaitUntil(condition); /// /// Convenience function to wait for a condition to return false. Equivalent to Unity's /// . /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WaitWhile While(Func condition) => new WaitWhile(condition); /// /// Convenience function to wait for a condition to return true. Equivalent to Unity's /// but state is passed to avoid closure. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WaitUntil Until(TState state, Func condition) => new WaitUntil(state, condition); /// /// Convenience function to wait for a condition to return false. Equivalent to Unity's /// but state is passed to avoid closure. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static WaitWhile While(TState state, Func condition) => new WaitWhile(state, condition); } }