WaitForFrames.cs 638 B

1234567891011121314151617181920212223242526272829
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. #endif
  4. namespace UnityAsync
  5. {
  6. public struct WaitForFrames : IAwaitInstruction
  7. {
  8. readonly int finishFrame;
  9. bool IAwaitInstruction.IsCompleted() => finishFrame <= AsyncManager.CurrentFrameCount;
  10. /// <summary>
  11. /// Waits for the specified number of frames to pass before continuing.
  12. /// </summary>
  13. public WaitForFrames(int count)
  14. {
  15. #if UNITY_EDITOR
  16. if(count <= 0)
  17. {
  18. count = 1;
  19. Debug.LogError($"{nameof(count)} should be greater than 0. This check will only appear in edit mode.");
  20. }
  21. #endif
  22. finishFrame = AsyncManager.CurrentFrameCount + count;
  23. }
  24. }
  25. }