| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace DCL |
| | 5 | | { |
| | 6 | | public class WaitUntil : CustomYieldInstruction |
| | 7 | | { |
| | 8 | | Func<bool> predicate; |
| | 9 | | float waitTime; |
| | 10 | | bool waitEnabled = false; |
| | 11 | |
|
| 423 | 12 | | public WaitUntil(Func<bool> predicate, float? timeoutInSeconds = null) |
| | 13 | | { |
| 423 | 14 | | this.predicate = predicate; |
| | 15 | |
|
| 423 | 16 | | if (timeoutInSeconds.HasValue) |
| | 17 | | { |
| 102 | 18 | | waitEnabled = true; |
| 102 | 19 | | waitTime = Time.realtimeSinceStartup + timeoutInSeconds.Value; |
| | 20 | | } |
| 423 | 21 | | } |
| | 22 | |
|
| | 23 | | public override bool keepWaiting |
| | 24 | | { |
| | 25 | | get |
| | 26 | | { |
| 2036 | 27 | | if (waitEnabled) |
| 591 | 28 | | return !predicate() && Time.realtimeSinceStartup < waitTime; |
| | 29 | | else |
| 1445 | 30 | | return !predicate(); |
| | 31 | | } |
| | 32 | | } |
| | 33 | | } |
| | 34 | | } |