public IEnumerator FastForwardInactiveBehavior() { // Given a delayed activation behavior with a positive delay time, IBehavior behavior = new DelayBehavior(0.05f); // When we mark it to fast-forward, behavior.LifeCycle.MarkToFastForward(); // Then it doesn't autocomplete because it hasn't been activated yet. Assert.AreEqual(Stage.Inactive, behavior.LifeCycle.Stage); yield break; }
public IEnumerator FastForwardInactiveBehaviorAndActivateIt() { // Given a delayed activation behavior with a positive delay time, IBehavior behavior = new DelayBehavior(0.1f); // When we mark it to fast-forward and activate it, behavior.LifeCycle.MarkToFastForward(); behavior.LifeCycle.Activate(); // Then the behavior should be activated immediately. Assert.AreEqual(Stage.Active, behavior.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 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 DelayBehavior() { // Given we have a training with a delayed activation behavior, ICourse training1 = new LinearTrainingBuilder("Training") .AddChapter(new LinearChapterBuilder("Chapter") .AddStep(new BasicStepBuilder("Step") .AddBehavior(new DelayBehavior(7f)))) .Build(); // When we serialize and deserialize it, byte[] serialized = Serializer.CourseToByteArray(training1); ICourse training2 = Serializer.CourseFromByteArray(serialized); // Then that delayed behaviors should have the same target behaviors and delay time. DelayBehavior behavior1 = training1.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as DelayBehavior; DelayBehavior behavior2 = training2.Data.FirstChapter.Data.FirstStep.Data.Behaviors.Data.Behaviors.First() as DelayBehavior; Assert.AreEqual(behavior1.Data.DelayTime, behavior2.Data.DelayTime); return(null); }
/// <inheritdoc /> public override IBehavior GetNewItem() { DelayBehavior delayBehavior = new DelayBehavior(5f); delayBehavior.Data.Name = "Wait for"; PlayAudioBehavior audioBehavior = new PlayAudioBehavior(new TextToSpeechAudio(new LocalizedString()), BehaviorExecutionStages.Activation); audioBehavior.Data.Name = "Play Audio"; BehaviorSequence behaviorSequence = new BehaviorSequence(true, new List <IBehavior> { delayBehavior, audioBehavior }); behaviorSequence.Data.Name = "Audio Hint"; behaviorSequence.Data.IsBlocking = false; return(behaviorSequence); }
public IEnumerator DoNotRepeat() { // Given a behaviors sequence with RepeatsMode = Once, DelayBehavior childBehavior = new DelayBehavior(shortDelay); BehaviorSequence sequence = new BehaviorSequence(false, new List <IBehavior> { childBehavior }); // When we activate it, sequence.LifeCycle.Activate(); yield return(null); sequence.Update(); // Then it completes its activation only after every child behavior was activated once. Assert.AreEqual(Stage.Activating, sequence.LifeCycle.Stage); Assert.AreEqual(Stage.Activating, childBehavior.LifeCycle.Stage); while (childBehavior.LifeCycle.Stage != Stage.Active) { yield return(null); sequence.Update(); } while (sequence.LifeCycle.Stage != Stage.Active) { yield return(null); sequence.Update(); Assert.AreNotEqual(Stage.Activating, childBehavior.LifeCycle.Stage); } Assert.AreEqual(Stage.Active, sequence.LifeCycle.Stage); // Cleanup. sequence.LifeCycle.Deactivate(); }
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); }