public IEnumerator FastForwardDeactivatingBehavior() { // Given a HighlightObjectBehavior with a HighlightProperty. Color highlightColor = Color.black; GameObject interactable = GameObject.CreatePrimitive(PrimitiveType.Cube); interactable.name = targetName; DummyHighlightProperty highlightProperty = interactable.AddComponent <DummyHighlightProperty>(); HighlightObjectBehavior highlightBehavior = new HighlightObjectBehavior(highlightProperty, highlightColor); highlightBehavior.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); highlightBehavior.LifeCycle.Activate(); while (highlightBehavior.LifeCycle.Stage != Stage.Active) { yield return(null); highlightBehavior.Update(); } highlightBehavior.LifeCycle.Deactivate(); // When we mark it to fast-forward. highlightBehavior.LifeCycle.MarkToFastForward(); // Then the behavior should be deactivated immediately. Assert.AreEqual(Stage.Inactive, highlightBehavior.LifeCycle.Stage); }
public IEnumerator HighlightColorIsSetByParameter() { // Given a HighlightProperty with a HighlightColor parameter set, DynamicRuntimeConfiguration testRuntimeConfiguration = new DynamicRuntimeConfiguration(); Color highlightColor = Color.green; testRuntimeConfiguration.SetAvailableModes(new List <IMode> { new Mode("Test", new WhitelistTypeRule <IOptional>(), new Dictionary <string, object> { { "HighlightColor", highlightColor } }), }); RuntimeConfigurator.Configuration = testRuntimeConfiguration; GameObject interactable = GameObject.CreatePrimitive(PrimitiveType.Cube); interactable.name = targetName; DummyHighlightProperty highlightProperty = interactable.AddComponent <DummyHighlightProperty>(); HighlightObjectBehavior highlightBehavior = new HighlightObjectBehavior(highlightProperty, highlightColor); highlightBehavior.Configure(testRuntimeConfiguration.Modes.CurrentMode); // When we activate it. highlightBehavior.LifeCycle.Activate(); // Then the highlight color is changed. Assert.AreEqual(highlightColor, highlightBehavior.Data.HighlightColor); Assert.AreEqual(highlightColor, highlightProperty.CurrentHighlightColor); Assert.AreEqual(highlightColor, ((HighlightProperty)highlightBehavior.Data.ObjectToHighlight).CurrentHighlightColor); yield break; }
public IEnumerator StepWithHighlightBehavior() { // Given a HighlightObjectBehavior with a HighlightProperty in a linear chapter. Color highlightColor = Color.yellow; GameObject interactable = GameObject.CreatePrimitive(PrimitiveType.Cube); interactable.name = targetName; DummyHighlightProperty highlightProperty = interactable.AddComponent <DummyHighlightProperty>(); HighlightObjectBehavior highlightBehavior = new HighlightObjectBehavior(highlightProperty, highlightColor); TestLinearChapterBuilder chapterBuilder = TestLinearChapterBuilder.SetupChapterBuilder(1); chapterBuilder.Steps[0].Data.Behaviors.Data.Behaviors.Add(highlightBehavior); Chapter chapter = chapterBuilder.Build(); chapter.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); // When we activate the chapter. chapter.LifeCycle.Activate(); while (highlightBehavior.LifeCycle.Stage != Stage.Active) { yield return(null); chapter.Update(); } Stage highlightStageInStep = highlightBehavior.LifeCycle.Stage; bool objectHighlightedActiveInStep = highlightProperty.IsHighlighted; Color?colorInStep = highlightProperty.CurrentHighlightColor; chapter.Data.FirstStep.LifeCycle.Deactivate(); while (chapter.Data.FirstStep.LifeCycle.Stage != Stage.Inactive) { yield return(null); chapter.Update(); } Stage highlightStageAfterStep = highlightBehavior.LifeCycle.Stage; bool objectHighlightedActiveAfterStep = highlightProperty.IsHighlighted; Color?colorAfterStep = highlightProperty.CurrentHighlightColor; // Then the highlight behavior is active during the step and inactive after it. Assert.AreEqual(Stage.Active, highlightStageInStep, "The HighlightObjectBehavior should be active during step"); Assert.IsTrue(objectHighlightedActiveInStep, "The HighlightProperty should be active during step"); Assert.AreEqual(highlightColor, colorInStep, $"The highlight color should be {highlightColor}"); Assert.AreEqual(Stage.Inactive, highlightStageAfterStep, "The HighlightObjectBehavior should be deactivated after step"); Assert.IsFalse(objectHighlightedActiveAfterStep, "The HighlightProperty should be inactive after step"); Assert.IsNull(colorAfterStep, "The highlight color should be null after deactivation of step."); }
public IEnumerator FastForwardInactiveBehavior() { // Given a HighlightObjectBehavior with a HighlightProperty. Color highlightColor = Color.cyan; GameObject interactable = GameObject.CreatePrimitive(PrimitiveType.Cube); interactable.name = targetName; DummyHighlightProperty highlightProperty = interactable.AddComponent <DummyHighlightProperty>(); HighlightObjectBehavior highlightBehavior = new HighlightObjectBehavior(highlightProperty, highlightColor); // When we mark it to fast-forward. highlightBehavior.LifeCycle.MarkToFastForward(); // Then it doesn't autocomplete because it hasn't been activated yet. Assert.AreEqual(Stage.Inactive, highlightBehavior.LifeCycle.Stage); yield break; }
public IEnumerator FastForwardActivatingBehavior() { // Given a HighlightObjectBehavior with a HighlightProperty. Color highlightColor = Color.blue; GameObject interactable = GameObject.CreatePrimitive(PrimitiveType.Cube); interactable.name = targetName; DummyHighlightProperty highlightProperty = interactable.AddComponent <DummyHighlightProperty>(); HighlightObjectBehavior highlightBehavior = new HighlightObjectBehavior(highlightProperty, highlightColor); // When we mark it active and fast-forward. highlightBehavior.LifeCycle.Activate(); highlightBehavior.LifeCycle.MarkToFastForward(); // Then the behavior should be activated immediately. Assert.AreEqual(Stage.Active, highlightBehavior.LifeCycle.Stage); yield break; }