Exemple #1
0
        public IEnumerator TestDisabledPointerCache()
        {
            TestButtonUtilities.InstantiateDefaultButton(TestButtonUtilities.DefaultButtonType.DefaultPushButton,
                                                         out Interactable interactable,
                                                         out Transform translateTargetObject);

            Vector3 targetStartPosition = translateTargetObject.localPosition;

            // Subscribe to interactable's on click so we know the click went through
            bool wasClicked = false;

            interactable.OnClick.AddListener(() => { wasClicked = true; });

            PlayModeTestUtilities.GetInputSimulationService().EnablePointerCache = false;

            var rightHand = new TestHand(Handedness.Right);

            yield return(rightHand.Show(Vector3.right));

            var rightPokePointer = PlayModeTestUtilities.GetPointer <PokePointer>(Handedness.Right);

            Assert.IsNotNull(rightPokePointer);
            Assert.IsFalse(rightPokePointer.DestroyOnSourceLost);

            yield return(TestButtonUtilities.TestClickPushButton(interactable.transform, targetStartPosition, translateTargetObject));

            Assert.IsTrue(wasClicked);
            Assert.IsTrue(rightPokePointer == null);
            Assert.IsNull(PlayModeTestUtilities.GetPointer <PokePointer>(Handedness.Right));

            wasClicked = false;
            yield return(TestButtonUtilities.TestClickPushButton(interactable.transform, targetStartPosition, translateTargetObject));

            Assert.IsTrue(wasClicked);
        }
        public IEnumerator TestDisableOnClick()
        {
            TestButtonUtilities.InstantiateDefaultButton(
                TestButtonUtilities.DefaultButtonType.DefaultPushButton,
                out Interactable interactable,
                out Transform innerCylinderTransform);

            Assert.True(interactable.IsEnabled);

            // OnClick, set Interactable IsEnabled false or aka disabled
            interactable.OnClick.AddListener(() => { interactable.IsEnabled = false; });

            // Get start position of the inner cylinder before button is pressed
            Vector3 innerCylinderStartPosition = innerCylinderTransform.localPosition;

            yield return(TestButtonUtilities.TestClickPushButton(interactable.transform, innerCylinderStartPosition, innerCylinderTransform));

            Assert.False(interactable.IsEnabled, "Interactable should be disabled");

            // Re-enable Interactable
            interactable.IsEnabled = true;
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            // Make sure the button depth is back at the starting position when re-enable the gameObject and states have reset
            Assert.True(innerCylinderTransform.localPosition == innerCylinderStartPosition);
            Assert.False(interactable.HasFocus, "Interactable has focus");
            Assert.True(interactable.IsVisited, "Interactable was not visited");

            GameObject.Destroy(interactable.gameObject);
        }
        public IEnumerator TestVoiceInputOnPrefab()
        {
            TestButtonUtilities.InstantiateDefaultButton(
                TestButtonUtilities.DefaultButtonType.DefaultPushButton,
                out Interactable interactable,
                out Transform translateTargetObject);

            // Subscribe to interactable's on click so we know the click went through
            bool wasClicked = false;

            interactable.OnClick.AddListener(() => { wasClicked = true; });

            Vector3 targetStartPosition = translateTargetObject.localPosition;

            // Set up its voice command
            interactable.VoiceCommand       = "Select";
            interactable.VoiceRequiresFocus = false;

            // Find an input source to associate with the input event (doesn't matter which one)
            IMixedRealityInputSource defaultInputSource = CoreServices.InputSystem.DetectedInputSources.FirstOrDefault();

            Assert.NotNull(defaultInputSource, "At least one input source must be present for this test to work.");

            //
            // Test speech when disabled
            //

            interactable.IsEnabled = false;

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            yield return(TestInputUtilities.ExecuteSpeechCommand(interactable.VoiceCommand, interactable.InputAction, defaultInputSource));

            yield return(TestButtonUtilities.CheckButtonTranslation(targetStartPosition, translateTargetObject, false));

            Assert.False(wasClicked, "Interactable was clicked.");
            Assert.False(interactable.IsVisited, "Interactable was visited.");

            //
            // Test speech when enabled
            //

            interactable.IsEnabled = true;

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            yield return(TestInputUtilities.ExecuteSpeechCommand(interactable.VoiceCommand, interactable.InputAction, defaultInputSource));

            yield return(TestButtonUtilities.CheckButtonTranslation(targetStartPosition, translateTargetObject));

            Assert.True(wasClicked, "Interactable was not clicked.");
            Assert.True(interactable.IsVisited, "Interactable was not visited.");

            GameObject.Destroy(interactable.gameObject);
        }
        public IEnumerator TestTouchInput()
        {
            TestButtonUtilities.InstantiateDefaultButton(
                TestButtonUtilities.DefaultButtonType.DefaultPushButton,
                out Interactable interactable,
                out Transform translateTargetObject);

            interactable.gameObject.AddComponent <NearInteractionTouchableVolume>();

            //
            // Test touch when disabled
            //

            interactable.IsEnabled = false;

            yield return(TestButtonUtilities.MoveHandToButton(interactable.transform));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.False(interactable.HasPhysicalTouch);
            Assert.False(interactable.HasPress);

            yield return(TestButtonUtilities.MoveHandAwayFromButton(interactable.transform));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            //
            // Test touch when enabled
            //

            interactable.IsEnabled = true;

            yield return(TestButtonUtilities.MoveHandToButton(interactable.transform));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.True(interactable.HasPhysicalTouch);
            Assert.True(interactable.HasPress);

            yield return(TestButtonUtilities.MoveHandAwayFromButton(interactable.transform));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.False(interactable.HasPhysicalTouch);
            Assert.False(interactable.HasPress);

            GameObject.Destroy(interactable.gameObject);
        }
        public IEnumerator TestSelectGlobalInput()
        {
            TestButtonUtilities.InstantiateDefaultButton(
                TestButtonUtilities.DefaultButtonType.DefaultPushButton,
                out Interactable interactable,
                out Transform translateTargetObject);

            interactable.transform.position = new Vector3(10f, 0.0f, 0.5f);

            // Subscribe to interactable's on click so we know the click went through
            bool wasClicked = false;

            interactable.OnClick.AddListener(() => { wasClicked = true; });

            // Set interactable to global and disabled
            interactable.IsEnabled = false;
            interactable.IsGlobal  = true;

            Vector3 targetStartPosition = translateTargetObject.localPosition;

            yield return(null);

            // Find an input source to associate with the input event (doesn't matter which one)
            IMixedRealityInputSource defaultInputSource = CoreServices.InputSystem.DetectedInputSources.FirstOrDefault();

            Assert.NotNull(defaultInputSource, "At least one input source must be present for this test to work.");

            yield return(RunGlobalClick(defaultInputSource, interactable.InputAction, targetStartPosition, translateTargetObject, false));

            Assert.False(wasClicked, "Interactable was not clicked.");
            Assert.False(interactable.HasFocus, "Interactable had focus");
            Assert.False(interactable.IsVisited, "Interactable was not visited");

            interactable.IsEnabled = true;

            yield return(RunGlobalClick(defaultInputSource, interactable.InputAction, targetStartPosition, translateTargetObject));

            Assert.True(wasClicked, "Interactable was not clicked.");
            Assert.False(interactable.HasFocus, "Interactable had focus");
            Assert.True(interactable.IsVisited, "Interactable was not visited");

            // Unregister global handlers
            interactable.IsGlobal = false;

            // Remove as global listener and cleanup
            GameObject.Destroy(interactable.gameObject);
        }
        public IEnumerator TestPressableToggleHoloLens2()
        {
            var     rightHand = new TestHand(Handedness.Right);
            Vector3 p2        = new Vector3(0.015f, 0f, 0.3f);

            TestButtonUtilities.InstantiateDefaultButton(
                TestButtonUtilities.DefaultButtonType.DefaultHL2ToggleButton,
                out Interactable interactable,
                out Transform frontPlateTransform);

            Assert.True(interactable.IsEnabled);
            interactable.transform.position = new Vector3(0.0f, 0.1f, 0.4f);

            bool wasClicked = false;

            interactable.OnClick.AddListener(() => { wasClicked = true; });

            // Get start position of the front plate before button is pressed
            Vector3 frontPlateStartPosition = frontPlateTransform.localPosition;

            yield return(rightHand.Show(p2));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.IsTrue(interactable.HasFocus, "Interactable does not have focus when hand is pointing at it.");

            int numClicks = 3;

            for (int i = 0; i < numClicks; i++)
            {
                wasClicked = false;
                yield return(rightHand.Click());

                // Wait for button animation to complete
                yield return(new WaitForSeconds(0.33f));

                Assert.True(wasClicked, "Toggle button was not clicked");
                Assert.AreEqual((i + 1) % 2, interactable.CurrentDimension, $"Toggle button is in incorrect toggle state on click {i}");

                // Make sure the button depth is back at the starting position
                Assert.True(frontPlateTransform.localPosition == frontPlateStartPosition, "Toggle button front plate did not return to starting position.");
            }

            GameObject.Destroy(interactable.gameObject);
        }
Exemple #7
0
        public IEnumerator TestPointerCaching()
        {
            TestButtonUtilities.InstantiateDefaultButton(TestButtonUtilities.DefaultButtonType.DefaultPushButton,
                                                         out Interactable interactable,
                                                         out Transform translateTargetObject);

            Vector3 targetStartPosition = translateTargetObject.localPosition;

            // Subscribe to interactable's on click so we know the click went through
            bool wasClicked = false;

            interactable.OnClick.AddListener(() => { wasClicked = true; });

            var rightHand = new TestHand(Handedness.Right);

            yield return(rightHand.Show(Vector3.right));

            var rightPokePointer = PlayModeTestUtilities.GetPointer <PokePointer>(Handedness.Right);

            Assert.IsNotNull(rightPokePointer);
            Assert.IsFalse(rightPokePointer.DestroyOnSourceLost);

            yield return(TestButtonUtilities.TestClickPushButton(interactable.transform, targetStartPosition, translateTargetObject));

            Assert.IsTrue(wasClicked);
            Assert.IsNotNull(rightPokePointer);
            Assert.IsNull(PlayModeTestUtilities.GetPointer <PokePointer>(Handedness.Right));

            wasClicked = false;

            yield return(rightHand.Show(Vector3.right));

            // Confirm that we are re-using the same pointer gameobject that was stored in the cache
            Assert.AreEqual(rightPokePointer, PlayModeTestUtilities.GetPointer <PokePointer>(Handedness.Right));

            yield return(TestButtonUtilities.TestClickPushButton(interactable.transform, targetStartPosition, translateTargetObject));

            Assert.IsTrue(wasClicked);
            Assert.IsNotNull(rightPokePointer);
            Assert.IsNull(PlayModeTestUtilities.GetPointer <PokePointer>(Handedness.Right));
        }
        public IEnumerator TestTriggerOnClick()
        {
            TestButtonUtilities.InstantiateDefaultButton(
                TestButtonUtilities.DefaultButtonType.DefaultPushButton,
                out Interactable interactable,
                out Transform innerCylinderTransform);

            // Subscribe to interactable's on click so we know the click went through
            bool wasClicked = false;

            interactable.OnClick.AddListener(() => { wasClicked = true; });

            Vector3 targetStartPosition = innerCylinderTransform.localPosition;

            //
            // Test TriggerOnClick when disabled
            //
            interactable.IsEnabled = false;

            interactable.TriggerOnClick();

            Assert.False(wasClicked, "Interactable was clicked.");
            Assert.False(interactable.IsVisited, "Interactable was visited.");

            //
            // Test TriggerOnClick when enabled
            //
            interactable.IsEnabled = true;

            interactable.TriggerOnClick();
            yield return(new WaitForSeconds(ButtonReleaseAnimationDelay));

            Assert.True(wasClicked, "Interactable was not clicked.");
            Assert.True(interactable.IsVisited, "Interactable was not visited.");

            GameObject.Destroy(interactable.gameObject);
        }
        public IEnumerator TestButtonStateResetWhenFocusLostAfterPinch()
        {
            TestButtonUtilities.InstantiateDefaultButton(
                TestButtonUtilities.DefaultButtonType.DefaultHL2Button,
                out Interactable interactable,
                out Transform interactableTransform);

            interactable.transform.position = new Vector3(0.0f, 0.1f, 0.4f);
            Assert.True(interactable.IsEnabled);

            var     rightHand     = new TestHand(Handedness.Right);
            Vector3 focusPosition = new Vector3(0.015f, 0.015f, 0.3f);
            Vector3 releaseDelta  = new Vector3(0.05f, 0, 0);

            // Focus the hand on the Button using the far ray pointer
            yield return(rightHand.Show(focusPosition));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.True(interactable.HasFocus);
            Assert.False(interactable.HasPress);
            Assert.False(interactable.HasGesture);
            Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Focus, "Interactable State is not Focus");

            // While keeping focus on the Button, engage the pinch gesture
            yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Pinch));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.True(interactable.HasFocus);
            Assert.True(interactable.HasPress);
            Assert.False(interactable.HasGesture);
            Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Pressed, "Interactable State is not Pressed");

            // Move Hand to remove focus. Button should go to Default State
            yield return(rightHand.Move(releaseDelta));

            yield return(new WaitForSeconds(0.25f));// Wait for Interactable rollOffTime for HasPress to reset

            Assert.False(interactable.HasFocus);
            Assert.False(interactable.HasPress);
            Assert.False(interactable.HasGesture);
            Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Default, "Interactable State is not Default");

            // Open hand. Button should stay on Default State
            yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Open));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.False(interactable.HasFocus);
            Assert.False(interactable.HasPress);
            Assert.False(interactable.HasGesture);
            Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Default, "Interactable State is not Default");

            // Move Hand back to Initial position and Pinch. Button should go to Pressed State
            yield return(rightHand.Move(-releaseDelta));

            yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Pinch));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.True(interactable.HasFocus);
            Assert.True(interactable.HasPress);
            Assert.False(interactable.HasGesture);
            Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Pressed, "Interactable State is not Pressed");

            // Open Hand. Button should go to Focus State
            yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Open));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.True(interactable.HasFocus);
            Assert.False(interactable.HasPress);
            Assert.False(interactable.HasGesture);
            Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Focus, "Interactable State is not Focus");

            GameObject.Destroy(interactable.gameObject);
        }
Exemple #10
0
        public IEnumerator TestButtonStateResetWhenFocusLostAfterPinch()
        {
            /// This test breaks if there is roll on the camera. I don't know if that's a real
            /// break, or an error in the test. Nulling out roll for now.
            Pose restorePose = TestUtilities.ArbitraryPlayspacePose;
            Pose noRollPose  = restorePose;

            noRollPose.rotation.eulerAngles      = new Vector3(noRollPose.rotation.eulerAngles.x, noRollPose.rotation.eulerAngles.y, 0.0f);
            TestUtilities.ArbitraryPlayspacePose = noRollPose;
            TestUtilities.PlayspaceToArbitraryPose();

            TestButtonUtilities.InstantiateDefaultButton(
                TestButtonUtilities.DefaultButtonType.DefaultHL2Button,
                out Interactable interactable,
                out Transform interactableTransform);

            interactable.transform.position = TestUtilities.PositionRelativeToPlayspace(new Vector3(0.0f, 0.1f, 0.4f));
            Assert.True(interactable.IsEnabled);

            var     rightHand     = new TestHand(Handedness.Right);
            Vector3 focusPosition = TestUtilities.PositionRelativeToPlayspace(new Vector3(0.0155f, 0.0145f, 0.3f));
            Vector3 releaseDelta  = TestUtilities.DirectionRelativeToPlayspace(new Vector3(0.05f, 0, 0));

            // Focus the hand on the Button using the far ray pointer
            yield return(rightHand.Show(focusPosition));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.True(interactable.HasFocus);
            Assert.False(interactable.HasPress);
            Assert.False(interactable.HasGesture);
            Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Focus, "Interactable State is not Focus");

            // While keeping focus on the Button, engage the pinch gesture
            yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Pinch));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.True(interactable.HasFocus);
            Assert.True(interactable.HasPress);
            Assert.False(interactable.HasGesture);
            Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Pressed, "Interactable State is not Pressed");

            // Move Hand to remove focus. Button should go to Default State
            yield return(rightHand.Move(releaseDelta));

            yield return(new WaitForSeconds(0.25f));// Wait for Interactable rollOffTime for HasPress to reset

            Assert.False(interactable.HasFocus);
            Assert.False(interactable.HasPress);
            Assert.False(interactable.HasGesture);
            Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Default, "Interactable State is not Default");

            // Open hand. Button should stay on Default State
            yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Open));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.False(interactable.HasFocus);
            Assert.False(interactable.HasPress);
            Assert.False(interactable.HasGesture);
            Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Default, "Interactable State is not Default");

            // Move Hand back to Initial position and Pinch. Button should go to Pressed State
            yield return(rightHand.Move(-releaseDelta));

            yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Pinch));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.True(interactable.HasFocus);
            Assert.True(interactable.HasPress);
            Assert.False(interactable.HasGesture);
            Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Pressed, "Interactable State is not Pressed");

            // Open Hand. Button should go to Focus State
            yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Open));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.True(interactable.HasFocus);
            Assert.False(interactable.HasPress);
            Assert.False(interactable.HasGesture);
            Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Focus, "Interactable State is not Focus");

            GameObject.Destroy(interactable.gameObject);

            TestUtilities.ArbitraryPlayspacePose = restorePose;
        }