Initial commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace BracerLib.Utility.Coroutines
|
||||
{
|
||||
[ExcludeFromCoverage]
|
||||
public class CancellableWaitForSeconds : CustomYieldInstruction
|
||||
{
|
||||
private float remaining;
|
||||
private readonly Func<bool> predicate;
|
||||
|
||||
public override bool keepWaiting => ShouldKeepWaiting();
|
||||
|
||||
public CancellableWaitForSeconds(float wait, Func<bool> predicate)
|
||||
{
|
||||
remaining = wait;
|
||||
this.predicate = predicate;
|
||||
}
|
||||
|
||||
private bool ShouldKeepWaiting()
|
||||
{
|
||||
remaining -= Time.deltaTime;
|
||||
var check = CheckCustomPredicate();
|
||||
|
||||
return !(check || remaining < 0f);
|
||||
}
|
||||
|
||||
private bool CheckCustomPredicate() => predicate?.Invoke() ?? false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user