WaitWhile.cs 514 B

123456789101112131415161718192021222324
  1. using System;
  2. namespace UnityAsync
  3. {
  4. public struct WaitWhile : IAwaitInstruction
  5. {
  6. readonly Func<bool> condition;
  7. bool IAwaitInstruction.IsCompleted() => !condition();
  8. /// <summary>
  9. /// Waits until the condition returns false before continuing.
  10. /// </summary>
  11. public WaitWhile(Func<bool> condition)
  12. {
  13. #if UNITY_EDITOR
  14. if(condition == null)
  15. throw new ArgumentNullException(nameof(condition), "This check only occurs in edit mode.");
  16. #endif
  17. this.condition = condition;
  18. }
  19. }
  20. }