public IEnumerator CompleteOnTargetedSnapZone() { // Setup object with mocked grabbed property and activate SnappablePropertyMock mockedProperty = CreateSnappablePropertyMock(); SnapZoneProperty snapZoneProperty = CreateSnapZoneProperty(); yield return(null); SnappedCondition condition = new SnappedCondition(mockedProperty, snapZoneProperty); condition.LifeCycle.Activate(); while (condition.LifeCycle.Stage != Stage.Active) { yield return(null); condition.Update(); } // Emit grabbed event mockedProperty.SetSnapZone(snapZoneProperty); mockedProperty.EmitSnapped(snapZoneProperty); while (condition.IsCompleted == false) { yield return(null); condition.Update(); } // Assert that condition is now completed Assert.IsTrue(condition.IsCompleted); }
public IEnumerator FastForwardDoesNotCompleteCondition() { // Given a snapped condition SnappablePropertyMock mockedProperty = CreateSnappablePropertyMock(); SnapZoneProperty snapZoneProperty = CreateSnapZoneProperty(); yield return(null); SnappedCondition condition = new SnappedCondition(mockedProperty, snapZoneProperty); // When you activate it, condition.LifeCycle.Activate(); while (condition.LifeCycle.Stage != Stage.Active) { yield return(null); condition.Update(); } // When you fast-forward it condition.LifeCycle.MarkToFastForward(); // Then nothing happens. Assert.AreEqual(Stage.Active, condition.LifeCycle.Stage); Assert.IsFalse(condition.IsCompleted); Assert.IsFalse(snapZoneProperty.IsObjectSnapped); }
public IEnumerator AutoCompleteActive() { // Given a snapped condition SnappablePropertyMock mockedProperty = CreateSnappablePropertyMock(); SnapZoneProperty snapZoneProperty = CreateSnapZoneProperty(); yield return(null); SnappedCondition condition = new SnappedCondition(mockedProperty, snapZoneProperty); // When you activate and autocomplete it, condition.LifeCycle.Activate(); while (condition.LifeCycle.Stage != Stage.Active) { yield return(null); condition.Update(); } condition.Autocomplete(); // Then the condition is completed and the object is snapped. Assert.AreEqual(Stage.Active, condition.LifeCycle.Stage); Assert.IsTrue(condition.IsCompleted); int beforeSnapped = Time.frameCount; yield return(new WaitUntil(() => snapZoneProperty.IsObjectSnapped)); int afterSnapped = Time.frameCount; Assert.IsTrue(snapZoneProperty.IsObjectSnapped); Assert.IsTrue(afterSnapped - beforeSnapped <= 3); }
public IEnumerator DontCompleteWhenSnappedWrongOnActivation() { // Setup object with mocked grabbed property and activate SnappablePropertyMock mockedProperty = CreateSnappablePropertyMock(); SnapZoneProperty snapZoneProperty = CreateSnapZoneProperty(); SnapZoneProperty wrongSnapZoneProperty = CreateSnapZoneProperty(); mockedProperty.SetSnapZone(wrongSnapZoneProperty); yield return(null); SnappedCondition condition = new SnappedCondition(mockedProperty, snapZoneProperty); condition.LifeCycle.Activate(); int frameCountEnd = Time.frameCount + 5; while (Time.frameCount <= frameCountEnd) { yield return(null); condition.Update(); } // Assert that condition is not completed Assert.IsFalse(condition.IsCompleted, "SnappedCondition should not be complete!"); }
public IEnumerator HighlightObjectNotShown() { // Given a snappable property with a snapzone highlight deactivated parameter active. DynamicRuntimeConfiguration testRuntimeConfiguration = new DynamicRuntimeConfiguration(); testRuntimeConfiguration.SetAvailableModes(new List <IMode> { new Mode("Test", new WhitelistTypeRule <IOptional>(), new Dictionary <string, object> { { "ShowSnapzoneHighlightObject", false } }), }); RuntimeConfigurator.Configuration = testRuntimeConfiguration; SnappablePropertyMock mockedProperty = CreateSnappablePropertyMock(); SnapZoneProperty snapZoneProperty = CreateSnapZoneProperty(); SnapZone zone = snapZoneProperty.SnapZone; mockedProperty.SetSnapZone(snapZoneProperty); yield return(null); SnappedCondition condition = new SnappedCondition(mockedProperty, snapZoneProperty); condition.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); yield return(null); condition.Update(); // When activated condition.LifeCycle.Activate(); while (condition.LifeCycle.Stage != Stage.Active) { yield return(null); condition.Update(); } // Then the highlight is still inactive. Assert.IsFalse(snapZoneProperty.SnapZone.ShowHighlightObject); }
public IEnumerator HighlightColorCanBeChanged() { // Given a snappable property with a highlight color changed DynamicRuntimeConfiguration testRuntimeConfiguration = new DynamicRuntimeConfiguration(); testRuntimeConfiguration.SetAvailableModes(new List <IMode> { new Mode("Test", new WhitelistTypeRule <IOptional>(), new Dictionary <string, object> { { "HighlightColor", Color.yellow } }), }); RuntimeConfigurator.Configuration = testRuntimeConfiguration; SnappablePropertyMock mockedProperty = CreateSnappablePropertyMock(); SnapZoneProperty snapZoneProperty = CreateSnapZoneProperty(); SnapZone zone = snapZoneProperty.SnapZone; mockedProperty.SetSnapZone(snapZoneProperty); yield return(null); SnappedCondition condition = new SnappedCondition(mockedProperty, snapZoneProperty); condition.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); yield return(null); condition.Update(); // When activated condition.LifeCycle.Activate(); while (condition.LifeCycle.Stage != Stage.Active) { yield return(null); condition.Update(); } // Then the highlight color changed properly Assert.AreEqual(Color.yellow, snapZoneProperty.SnapZone.ShownHighlightObjectColor); }
public IEnumerator HoverMeshShown() { // Given a snappable property with an AlwaysShowSnapzoneHighlight parameter set to false. DynamicRuntimeConfiguration testRuntimeConfiguration = new DynamicRuntimeConfiguration(); testRuntimeConfiguration.SetAvailableModes(new List <IMode> { new Mode("Test", new WhitelistTypeRule <IOptional>(), new Dictionary <string, object> { { "ShowSnapzoneHoverMeshes", true } }), }); RuntimeConfigurator.Configuration = testRuntimeConfiguration; SnappablePropertyMock mockedProperty = CreateSnappablePropertyMock(); SnapZoneProperty snapZoneProperty = CreateSnapZoneProperty(); SnapZone zone = snapZoneProperty.SnapZone; mockedProperty.SetSnapZone(snapZoneProperty); yield return(null); SnappedCondition condition = new SnappedCondition(mockedProperty, snapZoneProperty); condition.Configure(RuntimeConfigurator.Configuration.Modes.CurrentMode); // When activated condition.LifeCycle.Activate(); while (condition.LifeCycle.Stage != Stage.Active) { yield return(null); condition.Update(); } // Then the highlightAlwaysActive variable should be false Assert.IsTrue(snapZoneProperty.SnapZone.showInteractableHoverMeshes); }