public IEnumerator UnskipChildNotBlockingActive() { // Given an active nonblocking behavior with an optional child, OptionalEndlessBehavior optional = new OptionalEndlessBehavior(); NonblockingWrapperBehavior behavior = new NonblockingWrapperBehavior(optional, false); behavior.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehavior>())); behavior.LifeCycle.Activate(); while (behavior.LifeCycle.Stage != Stage.Active) { yield return(null); behavior.Update(); } // When a new mode is set and the optional child has to be reactivated, behavior.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>())); yield return(null); behavior.Update(); // The child is activating. Assert.AreEqual(Stage.Activating, optional.LifeCycle.Stage); yield break; }
public IEnumerator SkipChildNonBlockingActive() { // Given an active non-blocking behavior with an optional child, OptionalEndlessBehavior optional = new OptionalEndlessBehavior(); NonblockingWrapperBehavior behavior = new NonblockingWrapperBehavior(optional, false); behavior.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); behavior.LifeCycle.Activate(); optional.LifeCycle.MarkToFastForwardStage(Stage.Activating); while (optional.LifeCycle.Stage != Stage.Active) { yield return(null); behavior.Update(); } // When a new mode is set and the optional child has to be skipped, behavior.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehavior>())); while (behavior.LifeCycle.Stage != Stage.Active) { yield return(null); behavior.Update(); Assert.AreEqual(Stage.Inactive, optional.LifeCycle.Stage); } // The child is deactivated and behavior has finished it's activation. Assert.AreEqual(Stage.Inactive, optional.LifeCycle.Stage); Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage); yield break; }
public IEnumerator UnskipChild() { // Given an activating repeating behavior sequence of one not optional and one skipped optional behavior, OptionalEndlessBehavior optional = new OptionalEndlessBehavior(); EndlessBehavior notOptional = new EndlessBehavior(); BehaviorSequence sequence = new BehaviorSequence(true, new List <IBehavior> { notOptional, optional, }); sequence.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); sequence.LifeCycle.Activate(); yield return(null); sequence.Update(); notOptional.LifeCycle.MarkToFastForwardStage(Stage.Activating); notOptional.LifeCycle.MarkToFastForwardStage(Stage.Deactivating); sequence.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehavior>())); yield return(null); sequence.Update(); //When you re-enable it, sequence.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); notOptional.LifeCycle.MarkToFastForwardStage(Stage.Activating); notOptional.LifeCycle.MarkToFastForwardStage(Stage.Deactivating); while (optional.LifeCycle.Stage != Stage.Activating) { yield return(null); sequence.Update(); } // Then it is not skipped when it's its turn. Assert.AreEqual(Stage.Activating, optional.LifeCycle.Stage); }
public IEnumerator SkipChildNotWhenItIsExecuted() { // Given an activating behavior sequence of one not optional and one optional behavior, OptionalEndlessBehavior optional = new OptionalEndlessBehavior(); EndlessBehavior notOptional = new EndlessBehavior(); BehaviorSequence sequence = new BehaviorSequence(false, new List <IBehavior> { notOptional, optional, }); sequence.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); sequence.LifeCycle.Activate(); yield return(null); sequence.Update(); // When the optional behavior is marked to be skipped before it was its turn, sequence.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehavior>())); notOptional.LifeCycle.MarkToFastForwardStage(Stage.Activating); notOptional.LifeCycle.MarkToFastForwardStage(Stage.Deactivating); while (notOptional.LifeCycle.Stage != Stage.Inactive) { yield return(null); sequence.Update(); } while (sequence.LifeCycle.Stage != Stage.Active) { Assert.AreEqual(Stage.Inactive, optional.LifeCycle.Stage); yield return(null); sequence.Update(); } // Then it is skipped. Assert.AreEqual(Stage.Active, sequence.LifeCycle.Stage); yield break; }
public IEnumerator SkipChildBlockingDeactivating() { // Given a deactivating blocking behavior with an optional child, OptionalEndlessBehavior optional = new OptionalEndlessBehavior(); NonblockingWrapperBehavior behavior = new NonblockingWrapperBehavior(optional, true); behavior.Configure(RuntimeConfigurator.Configuration.GetCurrentMode()); behavior.LifeCycle.Activate(); optional.LifeCycle.MarkToFastForwardStage(Stage.Activating); while (optional.LifeCycle.Stage != Stage.Active) { yield return(null); behavior.Update(); } behavior.LifeCycle.Deactivate(); optional.LifeCycle.MarkToFastForwardStage(Stage.Deactivating); while (behavior.LifeCycle.Stage != Stage.Inactive) { yield return(null); behavior.Update(); } // When a new mode is set and the optional child has to be skipped, behavior.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehavior>())); // Wait a frame because configure doesn't even change anything about the stages. yield return(null); behavior.Update(); // The child is deactivated and behavior has finished its deactivation. Assert.AreEqual(Stage.Inactive, optional.LifeCycle.Stage); Assert.AreEqual(Stage.Inactive, behavior.LifeCycle.Stage); yield break; }
public IEnumerator SkipChildBlockingActivating() { // Given an activating blocking behavior with an optional child, OptionalEndlessBehavior optional = new OptionalEndlessBehavior(); NonblockingWrapperBehavior behavior = new NonblockingWrapperBehavior(optional, true); // When a new mode is set and the optional child has to be skipped, //RuntimeConfigurator.Configuration = new DynamicRuntimeConfiguration(new Mode("Test", new WhitelistTypeRule<IOptional>().Add<OptionalEndlessBehavior>())); behavior.Configure(new Mode("Test", new WhitelistTypeRule <IOptional>().Add <OptionalEndlessBehavior>())); behavior.LifeCycle.Activate(); while (behavior.LifeCycle.Stage != Stage.Active) { behavior.Update(); yield return(null); } // The child is deactivated and behavior has finished its activation. Assert.AreEqual(Stage.Inactive, optional.LifeCycle.Stage); Assert.AreEqual(Stage.Active, behavior.LifeCycle.Stage); yield break; }