Exemplo n.º 1
0
        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 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);
        }