public IEnumerator RunsInstantlyWhenDelayTimeIsZero() { // Given a delayed activation behavior with delay time == 0, IBehavior parentBehavior = new DelayBehavior(0f); // When we activate it, parentBehavior.LifeCycle.Activate(); parentBehavior.Update(); // Then the behavior should be activated immediately. Assert.AreEqual(Stage.Active, parentBehavior.LifeCycle.Stage); yield break; }
public IEnumerator NegativeTimeCompletesImmediately() { // Given a delayed activation behavior with negative delay time, DelayBehavior behavior = new DelayBehavior(-0.25f); // When we activate it, behavior.LifeCycle.Activate(); behavior.Update(); // Then the behavior should be activated immediately. Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage); yield break; }
public IEnumerator DoneAfterTime() { // Given a delayed activation behavior with a positive delay time, float delay = 0.1f; IBehavior behavior = new DelayBehavior(delay); // When we activate it and wait for it to be active, behavior.LifeCycle.Activate(); float startTime = Time.time; while (behavior.LifeCycle.Stage != Stage.Active) { behavior.Update(); yield return(null); } float duration = Time.time - startTime; // Then the behavior should be active after the specified delay, within a margin of error. Assert.GreaterOrEqual(duration, delay); Assert.LessOrEqual(duration, delay + 0.05f); }