Exemplo n.º 1
0
        public IEnumerator TestManualStartObserver()
        {
            var mrtkProfile = CreateMRTKTestProfile(TestSpatialAwarenessSystemProfilePath_ManualStart);

            TestUtilities.InitializeMixedRealityToolkit(mrtkProfile);
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            var spatialAwarenesssDataProvider = CoreServices.SpatialAwarenessSystem as IMixedRealityDataProviderAccess;
            var spatialObserver = spatialAwarenesssDataProvider.GetDataProvider <SpatialObjectMeshObserver.SpatialObjectMeshObserver>();

            Assert.IsNotNull(spatialObserver, "No SpatialObjectMeshObserver data provider created or found");
            Assert.IsFalse(spatialObserver.IsRunning);
            Assert.IsEmpty(spatialObserver.Meshes);

            CoreServices.SpatialAwarenessSystem.Disable();
            spatialObserver = spatialAwarenesssDataProvider.GetDataProvider <SpatialObjectMeshObserver.SpatialObjectMeshObserver>();
            Assert.IsNull(spatialObserver);

            CoreServices.SpatialAwarenessSystem.Enable();
            spatialObserver = spatialAwarenesssDataProvider.GetDataProvider <SpatialObjectMeshObserver.SpatialObjectMeshObserver>();
            Assert.IsNotNull(spatialObserver, "No SpatialObjectMeshObserver data provider created or found");
            Assert.IsFalse(spatialObserver.IsRunning);
            Assert.IsEmpty(spatialObserver.Meshes);

            CoreServices.SpatialAwarenessSystem.ResumeObservers();
            Assert.IsTrue(spatialObserver.IsRunning);
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.IsNotEmpty(spatialObserver.Meshes);

            CoreServices.SpatialAwarenessSystem.Disable();
            spatialObserver = spatialAwarenesssDataProvider.GetDataProvider <SpatialObjectMeshObserver.SpatialObjectMeshObserver>();
            Assert.IsNull(spatialObserver);

            CoreServices.SpatialAwarenessSystem.Enable();
            spatialObserver = spatialAwarenesssDataProvider.GetDataProvider <SpatialObjectMeshObserver.SpatialObjectMeshObserver>();
            Assert.IsNotNull(spatialObserver, "No SpatialObjectMeshObserver data provider created or found");
            Assert.IsFalse(spatialObserver.IsRunning);
            Assert.IsEmpty(spatialObserver.Meshes);
        }
        public IEnumerator TestGazeProviderDestroyed()
        {
            PlayModeTestUtilities.Setup();
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            // remove the gaze provider and it's components from the scene
            GazeProvider gazeProvider = CoreServices.InputSystem.GazeProvider.GameObjectReference.GetComponent <GazeProvider>();

            gazeProvider.GazePointer.BaseCursor.Destroy();
            DebugUtilities.LogVerbose("Application was playing, destroyed the gaze pointer's BaseCursor");
            UnityObjectExtensions.DestroyObject(gazeProvider as Component);
            gazeProvider = null;

            // Ensure that the input system and it's related input sources are able to be reinitialized without issue.
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            PlayModeTestUtilities.GetInputSystem().Initialize();

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            yield return(null);
        }
Exemplo n.º 3
0
        public IEnumerator GrabVolumesWithOverlap()
        {
            // Initialize overlapRect and cube
            overlapRect.SetActive(true);
            overlapRect.transform.localScale = Vector3.one * 2;
            overlapRect.transform.position   = Vector3.zero;

            cube.transform.localScale = Vector3.one;
            cube.transform.position   = Vector3.zero;

            // Initialize hand
            var rightHand = new TestHand(Handedness.Right);

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

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

            var pointer = rightHand.GetPointer <SpherePointer>();

            Assert.IsNotNull(pointer, "Expected to find SpherePointer in the hand controller");

            Assert.True(CoreServices.InputSystem.FocusProvider.GetFocusedObject(pointer) == cube, " the cube was not in focus");
            Assert.True(pointer.IsNearObject);
            Assert.True(pointer.IsInteractionEnabled);

            // Switch the scale of the cube and rect
            overlapRect.transform.localScale = Vector3.one;
            cube.transform.localScale        = Vector3.one * 2;

            // Wait for the input system to process the changes
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.True(CoreServices.InputSystem.FocusProvider.GetFocusedObject(pointer) == overlapRect, " the overlapping rectangle was not in focus");

            // Reinitialize the overlapRect
            overlapRect.SetActive(false);
        }
        public IEnumerator TestDisableOnClick()
        {
            // Load the Model_PushButton interactable prefab
            Interactable interactable;
            Transform    innerCylinderTransform;

            InstantiatePressableButtonPrefab(
                new Vector3(0.0f, 0.0f, 0.5f),
                DefaultRotation,
                DefaultInteractablePrefabAssetPath,
                "Cylinder",
                out interactable,
                out 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(TestClickPushButton(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);
        }
Exemplo n.º 5
0
        public IEnumerator TestPointerFOV()
        {
            var rightHand = new TestHand(Handedness.Right);

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

            cube.AddComponent <NearInteractionGrabbable>();
            cube.AddComponent <NearInteractionTouchableVolume>();
            yield return(rightHand.Show(Vector3.zero));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            var spherePointer = PointerUtils.GetPointer <SpherePointer>(Handedness.Right);
            var pokePointer   = PointerUtils.GetPointer <PokePointer>(Handedness.Right);

            yield return(TestPointerFOVHelper(spherePointer, cube, rightHand));

            yield return(TestPointerFOVHelper(pokePointer, cube, rightHand));

            rightHand.Hide();
            GameObject.Destroy(cube);
        }
Exemplo n.º 6
0
        public IEnumerator TestUseSourcePoseData()
        {
            TestHand rightHand = new TestHand(Handedness.Right);

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

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            PokePointer pokePointer = PointerUtils.GetPointer <PokePointer>(Handedness.Right);

            Assert.IsNotNull(pokePointer);
            SpherePointer grabPointer = PointerUtils.GetPointer <SpherePointer>(Handedness.Right);

            Assert.IsNotNull(grabPointer);

            pokePointer.UseSourcePoseData = true;
            grabPointer.UseSourcePoseData = true;
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            yield return(rightHand.Hide());

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

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());


            // The source pose is centered on the palm
            MixedRealityPose palmPose;

            HandJointUtils.TryGetJointPose(TrackedHandJoint.Palm, Handedness.Right, out palmPose);
            // This offset value is derived from the PokePointer's sourcePoseOffset property
            float pokePointerOffset = 0.075f;

            TestUtilities.AssertAboutEqual(pokePointer.Position, grabPointer.Position + pokePointer.transform.forward * pokePointerOffset, "pointer was not in the expected position");
            TestUtilities.AssertAboutEqual(grabPointer.Position, palmPose.Position, "pointer was not in the expected position");
        }
        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);
        }
        public IEnumerator TestInputActions()
        {
            AssembleInteractableButton(
                out Interactable interactable,
                out Transform translateTargetObject);

            interactable.transform.position    = new Vector3(0.0f, 0.0f, 0.5f);
            interactable.transform.eulerAngles = new Vector3(-90f, 0f, 0f);

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

            interactable.OnClick.AddListener(() => { wasClicked = true; });
            var  pressReceiver = interactable.AddReceiver <InteractableOnPressReceiver>();
            bool wasPressed    = false;

            pressReceiver.OnPress.AddListener(() => { wasPressed = true; Debug.Log("pressReciever wasPressed true"); });
            bool wasReleased = false;

            pressReceiver.OnRelease.AddListener(() => { wasReleased = true; Debug.Log("pressReciever wasReleased true"); });

            Vector3 targetStartPosition = translateTargetObject.localPosition;

            yield return(null);

            //
            // Test Select Input Action
            //

            // 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));

            Assert.True(wasClicked, "Interactable was not clicked.");
            Assert.True(wasPressed, "interactable not pressed");
            Assert.True(wasReleased, "interactable not released");
            Assert.AreEqual(targetStartPosition, translateTargetObject.localPosition, "Transform target object was not translated back by action.");

            //
            // Test Menu Input Action
            //

            // Find the menu action from the input system profile
            MixedRealityInputAction menuAction = CoreServices.InputSystem.InputSystemProfile.InputActionsProfile.InputActions.Where(m => m.Description == "Menu").FirstOrDefault();

            Assert.NotNull(menuAction.Description, "Couldn't find menu input action in input system profile.");

            // Set the interactable to respond to a 'menu' input action
            interactable.InputAction = menuAction;
            // Reset state tracking
            wasClicked = wasPressed = wasReleased = false;

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            yield return(RunGlobalClick(defaultInputSource, menuAction, targetStartPosition, translateTargetObject));

            Assert.True(wasClicked, "Interactable was not clicked.");
            Assert.True(wasPressed, "interactable not pressed");
            Assert.True(wasReleased, "interactable not released");
            Assert.AreEqual(targetStartPosition, translateTargetObject.localPosition, "Transform target object was not translated back by action.");

            GameObject.Destroy(interactable.gameObject);
        }
        public IEnumerator TestTeleport()
        {
            var iss = PlayModeTestUtilities.GetInputSimulationService();

            // Create a floor and make sure it's below the camera
            var floor = GameObject.CreatePrimitive(PrimitiveType.Plane);

            floor.transform.position = -0.5f * Vector3.up;

            // Test Right Hand Teleport
            TestUtilities.PlayspaceToOriginLookingForward();
            float initialForwardPosition = MixedRealityPlayspace.Position.z;

            TestHand leftHand  = new TestHand(Handedness.Left);
            TestHand rightHand = new TestHand(Handedness.Right);

            // Make sure the hand is in front of the camera
            yield return(rightHand.Show(Vector3.forward * 0.6f));

            rightHand.SetRotation(Quaternion.identity);

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

            // Wait for the hand to animate
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            yield return(new WaitForSeconds(1.0f / iss.InputSimulationProfile.HandGestureAnimationSpeed + 0.1f));

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

            // Wait for the hand to animate
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            yield return(new WaitForSeconds(1.0f / iss.InputSimulationProfile.HandGestureAnimationSpeed + 0.1f));

            // We should have teleported in the forward direction after the teleport
            Assert.IsTrue(MixedRealityPlayspace.Position.z > initialForwardPosition);
            rightHand.Hide();

            // Test Left Hand Teleport
            TestUtilities.PlayspaceToOriginLookingForward();

            // Make sure the hand is in front of the camera
            yield return(leftHand.Show(Vector3.forward * 0.6f));

            yield return(leftHand.SetGesture(ArticulatedHandPose.GestureId.TeleportStart));

            // Wait for the hand to animate
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            yield return(new WaitForSeconds(1.0f / iss.InputSimulationProfile.HandGestureAnimationSpeed + 0.1f));

            yield return(leftHand.SetGesture(ArticulatedHandPose.GestureId.TeleportEnd));

            // Wait for the hand to animate
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            yield return(new WaitForSeconds(1.0f / iss.InputSimulationProfile.HandGestureAnimationSpeed + 0.1f));

            // We should have teleported in the forward direction after the teleport
            Assert.IsTrue(MixedRealityPlayspace.Position.z > initialForwardPosition);
            leftHand.Hide();
        }
        public IEnumerator NearInteractionTouchableSetTouchableCollider()
        {
            GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

            cube.transform.position   = new Vector3(0, 0, 2f);
            cube.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);

            var rightHand = new TestHand(Handedness.Right);

            yield return(rightHand.Show(new Vector3(0, 0, 1.5f)));

            // Add NearInteractionTouchable
            var nearIT = cube.AddComponent <NearInteractionTouchable>();

            // Create new gameObject for testing a new BoxCollider
            GameObject cube2 = GameObject.CreatePrimitive(PrimitiveType.Cube);

            cube2.transform.position   = new Vector3(-1f, 0, 2f);
            cube2.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);

            using (var catcher = CreateTouchEventCatcher(nearIT))
            {
                // Touch started and completed when entering and exiting the collider
                yield return(rightHand.Move(new Vector3(0, 0, 0.4f)));

                yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

                Assert.AreEqual(1, catcher.EventsStarted);
                Assert.AreEqual(0, catcher.EventsCompleted);

                yield return(rightHand.Move(new Vector3(0, 0, -0.4f)));

                yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

                Assert.AreEqual(1, catcher.EventsStarted);
                Assert.AreEqual(1, catcher.EventsCompleted);

                // Set new touchableCollider bounds
                // Change touchableCollider to a new BoxCollider with a different size from another object
                BoxCollider newBoxCollider = cube2.GetComponent <BoxCollider>();
                newBoxCollider.size = new Vector3(4, 2, 1f);
                nearIT.SetTouchableCollider(newBoxCollider);

                // Move hand to the side
                yield return(rightHand.Move(new Vector3(-0.4f, 0, 0)));

                yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

                Assert.AreEqual(1, catcher.EventsStarted);
                Assert.AreEqual(1, catcher.EventsCompleted);

                // Move hand forward, on touch
                yield return(rightHand.Move(new Vector3(0, 0, 0.5f)));

                yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

                Assert.AreEqual(2, catcher.EventsStarted);

                // Move the hand back, on touch exit
                yield return(rightHand.Move(new Vector3(0, 0, -0.5f)));

                yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

                Assert.AreEqual(2, catcher.EventsCompleted);
            }
        }
        public IEnumerator TestVoiceInputOnPrefab()
        {
            // Load interactable prefab
            Interactable interactable;
            Transform    translateTargetObject;

            InstantiatePressableButtonPrefab(
                new Vector3(0.0f, 0.0f, 0.5f),
                DefaultRotation,
                DefaultInteractablePrefabAssetPath,
                "Cylinder",
                out interactable,
                out 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(FireSpeechCommand(interactable.VoiceCommand, interactable.InputAction, defaultInputSource));

            yield return(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(FireSpeechCommand(interactable.VoiceCommand, interactable.InputAction, defaultInputSource));

            yield return(CheckButtonTranslation(targetStartPosition, translateTargetObject));

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

            //Cleanup
            GameObject.Destroy(interactable.gameObject);
        }
        public IEnumerator TestDialogPrefabResults()
        {
            TestHand handRight = new TestHand(Handedness.Right);
            int      handsteps = 80;

            // Testing near interactions
            handRight.Show(Vector3.zero);
            InstantiateFromPrefab("Test Dialog", "This is an example dialog", DialogButtonType.OK, true);

            // Wait for the dialog to move to a stable position
            yield return(new WaitForSeconds(DialogStabilizationTime));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.IsTrue(dialogComponent.State == DialogState.WaitingForInput);
            yield return(handRight.Move(new Vector3(0.0f, -0.1f, 1.0f), handsteps));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.AreEqual(dialogResult, DialogButtonType.OK);
            Assert.AreEqual(dialogComponent.State, DialogState.Closed);

            GameObject.Destroy(dialogGameObject);
            GameObject.Destroy(dialogComponent);
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            // The dialog only supports displaying up to two options
            yield return(handRight.MoveTo(Vector3.zero));

            InstantiateFromPrefab("Test Dialog", "This is an example dialog", DialogButtonType.Yes | DialogButtonType.No, true);

            // Wait for the dialog to move to a stable position
            yield return(new WaitForSeconds(DialogStabilizationTime));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.IsTrue(dialogComponent.State == DialogState.WaitingForInput);
            yield return(handRight.Move(new Vector3(0.1f, -0.1f, 1.0f), handsteps));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.AreEqual(dialogResult, DialogButtonType.No);
            Assert.AreEqual(dialogComponent.State, DialogState.Closed);

            GameObject.Destroy(dialogGameObject);
            GameObject.Destroy(dialogComponent);
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            // Testing far interactions
            // The dialog only supports displaying up to two options
            yield return(handRight.MoveTo(Vector3.zero));

            InstantiateFromPrefab("Test Dialog", "This is an example dialog", DialogButtonType.Yes | DialogButtonType.No, false);

            // Wait for the dialog to move to a stable position
            yield return(new WaitForSeconds(DialogStabilizationTime));


            Assert.IsTrue(dialogComponent.State == DialogState.WaitingForInput);
            // moving the hand to an appropriate position to click on the dialog
            yield return(handRight.Move(new Vector3(-0.1f, -0.2f, 0.7f), handsteps));

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

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            yield return(handRight.SetGesture(ArticulatedHandPose.GestureId.Open));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.AreEqual(dialogResult, DialogButtonType.Yes);
            Assert.AreEqual(dialogComponent.State, DialogState.Closed);

            GameObject.Destroy(dialogGameObject);
            GameObject.Destroy(dialogComponent);
        }
        public IEnumerator TestAssembleSnapSlider()
        {
            GameObject  pinchSliderObject;
            PinchSlider slider;

            // This should not throw exception
            AssembleSlider(Vector3.forward, Vector3.zero, out pinchSliderObject, out slider);

            // Set the slider to use step divisions
            slider.UseSliderStepDivisions = true;
            slider.SliderStepDivisions    = 4;

            // Set slider to snap without touch
            slider.SnapToPosition = true;
            slider.IsTouchable    = false;

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            bool interactionStarted = false;

            slider.OnInteractionStarted.AddListener((x) => interactionStarted = true);
            bool interactionUpdated = false;

            slider.OnValueUpdated.AddListener((x) => interactionUpdated = true);

            var     rightHand  = new TestHand(Handedness.Right);
            Vector3 initialPos = new Vector3(0.3f, 0, 0.0f);

            yield return(rightHand.Show(initialPos));

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

            yield return(rightHand.Move(new Vector3(0, 0, 1.0f)));

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.IsFalse(interactionStarted, "Slider raised interaction started early.");
            Assert.IsFalse(interactionUpdated, "Slider raised SliderUpdated event early.");

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

            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            Assert.IsTrue(interactionStarted, "Slider did not raise interaction started.");
            Assert.IsTrue(interactionUpdated, "Slider did not raise SliderUpdated event.");

            Assert.AreEqual(0.75f, slider.SliderValue);

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

            yield return(rightHand.Move(new Vector3(-0.6f, 0, 0)));

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

            Assert.AreEqual(0.25f, slider.SliderValue);

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

            yield return(rightHand.Move(new Vector3(0.3f, 0, 0)));

            Assert.AreEqual(0.25f, slider.SliderValue);

            bool interactionEnded = false;

            slider.OnInteractionEnded.AddListener((x) => interactionEnded = true);

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

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

            yield return(rightHand.Hide());

            Assert.IsTrue(interactionEnded, "Slider did not raise interaction ended.");

            GameObject.Destroy(pinchSliderObject);
        }
Exemplo n.º 14
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;
        }
        public IEnumerator TestTeleportAndContentOffset()
        {
            var             iss = PlayModeTestUtilities.GetInputSimulationService();
            ExperienceScale originalExperienceScale;
            float           originalProfileContentOffset;

            float contentOffset = 1.3f;

            // MRTK has already been created by SetUp prior to calling this,
            // we have to shut it down to re-init with the custom input profile which
            // has our contentOffset value set
            PlayModeTestUtilities.TearDown();
            yield return(null);

            // Initialize a profile with the appropriate contentOffset
            var profile = TestUtilities.GetDefaultMixedRealityProfile <MixedRealityToolkitConfigurationProfile>();

            originalProfileContentOffset = profile.ExperienceSettingsProfile.ContentOffset;
            originalExperienceScale      = profile.ExperienceSettingsProfile.TargetExperienceScale;

            profile.ExperienceSettingsProfile.ContentOffset         = contentOffset;
            profile.ExperienceSettingsProfile.TargetExperienceScale = ExperienceScale.Room;

            PlayModeTestUtilities.Setup(profile);

            yield return(new WaitForSeconds(0.5f));

            // Ensure that the SceneContent object is contentOffset units above the origin
            Assert.AreEqual(GameObject.Find("MixedRealitySceneContent").transform.position.y, contentOffset, 0.005f);

            // Create a floor and make sure it's below the camera
            var floor = GameObject.CreatePrimitive(PrimitiveType.Plane);

            floor.transform.position = -0.5f * Vector3.up;

            // Test Right Hand Teleport
            TestUtilities.PlayspaceToOriginLookingForward();
            float initialForwardPosition = MixedRealityPlayspace.Position.z;

            TestHand leftHand  = new TestHand(Handedness.Left);
            TestHand rightHand = new TestHand(Handedness.Right);

            // Make sure the hand is in front of the camera
            yield return(rightHand.Show(Vector3.forward * 0.6f));

            rightHand.SetRotation(Quaternion.identity);

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

            // Wait for the hand to animate
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            yield return(new WaitForSeconds(1.0f / iss.InputSimulationProfile.HandGestureAnimationSpeed + 0.1f));

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

            // Wait for the hand to animate
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            yield return(new WaitForSeconds(1.0f / iss.InputSimulationProfile.HandGestureAnimationSpeed + 0.1f));

            // We should have teleported in the forward direction after the teleport
            Assert.IsTrue(MixedRealityPlayspace.Position.z > initialForwardPosition);
            rightHand.Hide();

            // Test Left Hand Teleport
            TestUtilities.PlayspaceToOriginLookingForward();

            // Make sure the hand is in front of the camera
            yield return(leftHand.Show(Vector3.forward * 0.6f));

            yield return(leftHand.SetGesture(ArticulatedHandPose.GestureId.TeleportStart));

            // Wait for the hand to animate
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            yield return(new WaitForSeconds(1.0f / iss.InputSimulationProfile.HandGestureAnimationSpeed + 0.1f));

            yield return(leftHand.SetGesture(ArticulatedHandPose.GestureId.TeleportEnd));

            // Wait for the hand to animate
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());

            yield return(new WaitForSeconds(1.0f / iss.InputSimulationProfile.HandGestureAnimationSpeed + 0.1f));

            // We should have teleported in the forward direction after the teleport
            Assert.IsTrue(MixedRealityPlayspace.Position.z > initialForwardPosition);

            // Reset the profile's settings to it's original value
            profile.ExperienceSettingsProfile.TargetExperienceScale = originalExperienceScale;
            profile.ExperienceSettingsProfile.ContentOffset         = originalProfileContentOffset;

            leftHand.Hide();
        }