WaitUntilWithTimeout.cs 827 B

123456789101112131415161718192021222324252627282930313233
  1. using UnityEngine;
  2. namespace Unity.WebRTC.RuntimeTest
  3. {
  4. internal class WaitUntilWithTimeout : CustomYieldInstruction
  5. {
  6. public bool IsCompleted { get; private set; }
  7. private readonly float timeoutTime;
  8. private readonly System.Func<bool> predicate;
  9. public override bool keepWaiting
  10. {
  11. get
  12. {
  13. IsCompleted = predicate();
  14. if (IsCompleted)
  15. {
  16. return false;
  17. }
  18. return !(Time.realtimeSinceStartup >= timeoutTime);
  19. }
  20. }
  21. public WaitUntilWithTimeout(System.Func<bool> predicate, int timeout)
  22. {
  23. this.timeoutTime = Time.realtimeSinceStartup + timeout * 0.001f;
  24. this.predicate = predicate;
  25. }
  26. }
  27. }