public IEnumerator NearInteractionTouchableUnityUiButton()
        {
            var canvas = UnityUiUtilities.CreateCanvas(0.002f);

            var button = UnityUiUtilities.CreateButton(Color.gray, Color.blue, Color.green);

            button.transform.SetParent(canvas.transform, false);
            var text = UnityUiUtilities.CreateText("test");

            text.transform.SetParent(button.transform, false);

            Vector3 pressedPosition = objectPosition + Vector3.forward * 0.05f;

            canvas.transform.position = objectPosition;

            yield return(new WaitForFixedUpdate());

            yield return(null);

            yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSim));

            using (var catcher = new UnityButtonEventCatcher(button))
            {
                // Touch started and completed when entering and exiting
                yield return(PlayModeTestUtilities.MoveHand(initialHandPosition, pressedPosition, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim));

                Assert.AreEqual(0, catcher.Click);
                yield return(PlayModeTestUtilities.MoveHand(pressedPosition + Vector3.forward * 0.05f, initialHandPosition, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim));

                Assert.AreEqual(1, catcher.Click);
            }

            Object.Destroy(canvas.gameObject);
        }
        /// <summary>
        /// Move the right hand from point 1 to point 2
        /// </summary>
        public static IEnumerator MoveHand(Vector3 p1, Vector3 p2)
        {
            // Move the hand towards
            var inputSimulationService = PlayModeTestUtilities.GetInputSimulationService();

            yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSimulationService));

            yield return(PlayModeTestUtilities.MoveHand(p1, p2, ArticulatedHandPose.GestureId.Poke, Handedness.Right, inputSimulationService));
        }
Пример #3
0
 /// <summary>
 /// Changes the hand's pose to the given gesture.  Does not animate the hand between the current pose and new pose.
 /// </summary>
 /// <param name="newGestureId">The new hand pose</param>
 /// <param name="waitForFixedUpdate">If true, waits for a fixed update after moving to the new pose.</param>
 public IEnumerator SetGesture(ArticulatedHandPose.GestureId newGestureId, bool waitForFixedUpdate = true)
 {
     gestureId = newGestureId;
     for (var iter = PlayModeTestUtilities.MoveHand(position, position, gestureId, handedness, simulationService, 1); iter.MoveNext();)
     {
         yield return(iter.Current);
     }
     if (waitForFixedUpdate)
     {
         yield return(new WaitForFixedUpdate());
     }
 }
Пример #4
0
        /// <summary>
        /// Move the right from in the button to just in front of the button
        /// </summary>
        public static IEnumerator MoveHandAwayFromButton(Transform button)
        {
            Vector3 p2 = button.transform.position;
            Vector3 p3 = button.transform.position - button.TransformDirection(ButtonTranslateOffset);

            // Move the hand back
            var inputSimulationService = PlayModeTestUtilities.GetInputSimulationService();

            yield return(PlayModeTestUtilities.MoveHand(p2, p3, ArticulatedHandPose.GestureId.Poke, Handedness.Right, inputSimulationService));

            yield return(PlayModeTestUtilities.HideHand(Handedness.Right, inputSimulationService));
        }
Пример #5
0
        /// <summary>
        /// Move the right hand from in front of the button through to the button
        /// </summary>
        public static IEnumerator MoveHandToButton(Transform button)
        {
            Vector3 p1 = button.transform.position - button.TransformDirection(ButtonTranslateOffset);
            Vector3 p2 = button.transform.position;

            // Move the hand towards
            var inputSimulationService = PlayModeTestUtilities.GetInputSimulationService();

            yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSimulationService));

            yield return(PlayModeTestUtilities.MoveHand(p1, p2, ArticulatedHandPose.GestureId.Poke, Handedness.Right, inputSimulationService));
        }
Пример #6
0
        /// <summary>
        /// Moves hand to given position over some number of frames.
        /// </summary>
        /// <param name="newPosition">Where to move hand to</param>
        /// <param name="numSteps">
        /// How many frames to move over. This defaults to the "sentinel" value which tells the system
        /// to use the default number of steps. For more information on this value, see
        /// <see cref="PlayModeTestUtilities.HandMoveStepsSentinelValue"/>
        /// </param>
        /// <param name="waitForFixedUpdate">If true, waits a physics frame after moving the hand</param>
        public IEnumerator MoveTo(Vector3 newPosition, int numSteps = PlayModeTestUtilities.HandMoveStepsSentinelValue, bool waitForFixedUpdate = true)
        {
            Vector3 oldPosition = position;

            position = newPosition;
            for (var iter = PlayModeTestUtilities.MoveHand(oldPosition, newPosition, gestureId, handedness, simulationService, numSteps); iter.MoveNext();)
            {
                yield return(iter.Current);
            }
            if (waitForFixedUpdate)
            {
                yield return(new WaitForFixedUpdate());
            }
        }
        public IEnumerator NearInteractionTouchableOverlapQuerySaturation()
        {
            // Use all the points
            int numTouchables = NumRandomPoints;
            var touchables    = new NearInteractionTouchable[numTouchables];
            var catchers      = new TouchEventCatcher[numTouchables];

            // Spread out touchables over a radius, decrease over time to increase density and fill the buffer
            float radiusStart = 1.0f;
            float radiusEnd   = 0.01f;

            for (int i = 0; i < numTouchables; ++i)
            {
                Vector3 r = GetRandomPoint(i);

                touchables[i] = CreateTouchable <NearInteractionTouchable>(0.15f);
                touchables[i].SetLocalForward(touchNormal);
                touchables[i].SetBounds(new Vector2(0.5f, 0.5f));
                touchables[i].transform.position = objectPosition + r * radiusStart;

                catchers[i] = CreateTouchEventCatcher(touchables[i]);
            }

            yield return(new WaitForFixedUpdate());

            yield return(null);

            yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSim));

            yield return(PlayModeTestUtilities.MoveHand(initialHandPosition, objectPosition, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim, 1));

            for (int i = 0; i < PlayModeTestUtilities.ControllerMoveSteps; ++i)
            {
                float scale = radiusStart + (radiusEnd - radiusStart) * (i + 1) / PlayModeTestUtilities.ControllerMoveSteps;
                for (int j = 0; j < numTouchables; ++j)
                {
                    Vector3 r = GetRandomPoint(j + 10);
                    touchables[j].transform.position = objectPosition + r * scale;
                }
                yield return(null);
            }

            yield return(PlayModeTestUtilities.HideHand(Handedness.Right, inputSim));

            foreach (NearInteractionTouchable touchable in touchables)
            {
                Object.Destroy(touchable.gameObject);
            }
        }
        /// <summary>
        /// Move the hand forward to press button, then off to the right
        /// </summary>
        private IEnumerator PressButtonWithHand()
        {
            var     inputSimulationService = PlayModeTestUtilities.GetInputSimulationService();
            Vector3 p1 = new Vector3(0, 0, 0.5f);
            Vector3 p2 = new Vector3(0, 0, 1.08f);
            Vector3 p3 = new Vector3(0.1f, 0, 1.08f);

            yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSimulationService, ArticulatedHandPose.GestureId.Open, p1));

            yield return(PlayModeTestUtilities.MoveHand(p1, p2, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSimulationService));

            yield return(PlayModeTestUtilities.MoveHand(p2, p3, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSimulationService));

            yield return(PlayModeTestUtilities.HideHand(Handedness.Right, inputSimulationService));
        }
        public IEnumerator NearInteractionTouchableStack()
        {
            // Ignoring this test for now, as it needs fixing
            Assert.Ignore();

            int numTouchables = 10;
            var touchables    = new NearInteractionTouchable[numTouchables];
            var catchers      = new TouchEventCatcher[numTouchables];

            for (int i = 0; i < numTouchables; ++i)
            {
                Vector3 r = GetRandomPoint(i);

                touchables[i] = CreateTouchable <NearInteractionTouchable>(0.15f);
                touchables[i].SetLocalForward(touchNormal);
                touchables[i].SetBounds(new Vector2(0.5f, 0.5f));
                touchables[i].transform.position = objectPosition + new Vector3(0.02f * r.x, 0.015f * r.y, 0.1f * i - 0.5f);

                catchers[i] = CreateTouchEventCatcher(touchables[i]);
            }

            yield return(new WaitForFixedUpdate());

            yield return(null);

            yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSim));

            yield return(PlayModeTestUtilities.MoveHand(initialHandPosition, objectPosition, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim));

            // No. 0 is touched initially
            TestEvents(catchers, new int[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, new int[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
            yield return(PlayModeTestUtilities.MoveHand(objectPosition, rightPosition, ArticulatedHandPose.GestureId.Pinch, Handedness.Right, inputSim));

            // Only No. 3 gets touched when moving through the row, because No. 0 is still active while inside the poke threshold
            TestEvents(catchers, new int[] { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, new int[] { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0 });
            yield return(PlayModeTestUtilities.MoveHand(rightPosition, objectPosition, ArticulatedHandPose.GestureId.Pinch, Handedness.Right, inputSim));

            // No. 3 touched a second time
            TestEvents(catchers, new int[] { 1, 0, 0, 2, 0, 0, 0, 0, 0, 0 }, new int[] { 1, 0, 0, 2, 0, 0, 0, 0, 0, 0 });

            yield return(PlayModeTestUtilities.HideHand(Handedness.Right, inputSim));

            foreach (NearInteractionTouchable touchable in touchables)
            {
                Object.Destroy(touchable.gameObject);
            }
        }
        public IEnumerator NearInteractionTouchableUnityUiToggle()
        {
            var canvas = UnityUiUtilities.CreateCanvas(0.002f);

            var toggle = UnityUiUtilities.CreateToggle(Color.gray, Color.blue, Color.green);

            toggle.transform.SetParent(canvas.transform, false);
            var text = UnityUiUtilities.CreateText("test");

            text.transform.SetParent(toggle.transform, false);

            Vector3 pressedPosition = objectPosition + Vector3.forward * 0.05f;

            canvas.transform.position = objectPosition;

            yield return(new WaitForFixedUpdate());

            yield return(null);

            yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSim));

            using (var catcher = new UnityToggleEventCatcher(toggle))
            {
                // Turn on the toggle after exiting
                yield return(PlayModeTestUtilities.MoveHand(initialHandPosition, pressedPosition, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim));

                Assert.IsFalse(catcher.IsOn);
                Assert.AreEqual(0, catcher.Changed);
                yield return(PlayModeTestUtilities.MoveHand(pressedPosition, initialHandPosition, ArticulatedHandPose.GestureId.Pinch, Handedness.Right, inputSim));

                Assert.IsTrue(catcher.IsOn);
                Assert.AreEqual(1, catcher.Changed);

                // Turn off the toggle after exiting
                yield return(PlayModeTestUtilities.MoveHand(initialHandPosition, pressedPosition, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim));

                Assert.IsTrue(catcher.IsOn);
                Assert.AreEqual(1, catcher.Changed);
                yield return(PlayModeTestUtilities.MoveHand(pressedPosition, initialHandPosition, ArticulatedHandPose.GestureId.Pinch, Handedness.Right, inputSim));

                Assert.IsFalse(catcher.IsOn);
                Assert.AreEqual(2, catcher.Changed);
            }

            Object.Destroy(canvas.gameObject);
        }
        public IEnumerator PressButtonFast([ValueSource(nameof(PressableButtonsTestPrefabFilenames))] string prefabFilename)
        {
            GameObject testButton = InstantiateDefaultPressableButton(prefabFilename);

            // Move the camera to origin looking at +z to more easily see the button.
            TestUtilities.PlayspaceToOriginLookingForward();

            PressableButton buttonComponent = testButton.GetComponent <PressableButton>();

            Assert.IsNotNull(buttonComponent);
            Assert.IsTrue(buttonComponent.EnforceFrontPush, "Button default behavior should have enforce front push enabled");

            bool buttonPressed = false;

            buttonComponent.ButtonPressed.AddListener(() =>
            {
                buttonPressed = true;
            });

            // move the hand quickly from very far distance into the button and check if it was pressed
            var     inputSimulationService = PlayModeTestUtilities.GetInputSimulationService();
            int     numSteps = 2;
            Vector3 p1       = new Vector3(0, 0, -20.0f);
            Vector3 p2       = new Vector3(0, 0, 0.02f);

            yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSimulationService));

            yield return(PlayModeTestUtilities.MoveHand(p1, p2, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSimulationService, numSteps));

            yield return(PlayModeTestUtilities.HideHand(Handedness.Right, inputSimulationService));

            Assert.IsTrue(buttonPressed, "Button did not get pressed when hand moved to press it.");

            Object.Destroy(testButton);

            yield return(null);
        }
        private IEnumerator TestTouchableDistances(BaseNearInteractionTouchable touchable, float colliderThickness, GameObject objectDownExpected)
        {
            Handedness handedness = Handedness.Right;

            ArticulatedHandPose.GestureId gesture = ArticulatedHandPose.GestureId.Open;

            yield return(PlayModeTestUtilities.ShowHand(handedness, inputSim));

            PokePointer       pokePointer = null;
            IMixedRealityHand hand        = HandJointUtils.FindHand(handedness);

            Assert.IsNotNull(hand);
            foreach (IMixedRealityPointer pointer in hand.InputSource.Pointers)
            {
                pokePointer = pointer as PokePointer;
                if (pokePointer)
                {
                    break;
                }
            }
            Assert.IsNotNull(pokePointer);
            float touchableDistance = pokePointer.TouchableDistance;

            float debounceThreshold = 0.01f;

            touchable.DebounceThreshold = debounceThreshold;

            Vector3 center = touchable.transform.position;

            float   margin    = 0.001f;
            Vector3 pStart    = center + new Vector3(0, 0, -touchableDistance - 0.5f);
            Vector3 pTouch    = center + new Vector3(0, 0, -touchableDistance + margin);
            Vector3 pPoke     = center + new Vector3(0, 0, -colliderThickness + margin);
            Vector3 pDebounce = center + new Vector3(0, 0, -colliderThickness - touchable.DebounceThreshold - margin);
            Vector3 pEnd      = center + new Vector3(0, 0, touchableDistance + 0.5f);

            // Test return beyond DebounceThreshold
            yield return(PlayModeTestUtilities.MoveHand(pStart, pStart, gesture, handedness, inputSim, 1));

            Assert.IsNull(pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pStart, pTouch, gesture, handedness, inputSim));

            Assert.AreEqual(touchable, pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pTouch, pPoke, gesture, handedness, inputSim));

            Assert.AreEqual(touchable, pokePointer.ClosestProximityTouchable);
            Assert.AreEqual(objectDownExpected, pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pPoke, pDebounce, gesture, handedness, inputSim));

            Assert.AreEqual(touchable, pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pDebounce, pStart, gesture, handedness, inputSim));

            Assert.IsNull(pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            // Test touchable distance behind the surface
            yield return(PlayModeTestUtilities.MoveHand(pStart, pStart, gesture, handedness, inputSim, 1));

            Assert.IsNull(pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pStart, pTouch, gesture, handedness, inputSim));

            Assert.AreEqual(touchable, pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pTouch, pPoke, gesture, handedness, inputSim));

            Assert.AreEqual(touchable, pokePointer.ClosestProximityTouchable);
            Assert.AreEqual(objectDownExpected, pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pPoke, pEnd, gesture, handedness, inputSim));

            Assert.IsNull(pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pEnd, pDebounce, gesture, handedness, inputSim));

            Assert.AreEqual(touchable, pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.MoveHand(pDebounce, pStart, gesture, handedness, inputSim));

            Assert.IsNull(pokePointer.ClosestProximityTouchable);
            Assert.IsNull(pokePointer.CurrentTouchableObjectDown);

            yield return(PlayModeTestUtilities.HideHand(handedness, inputSim));
        }