Exemplo n.º 1
0
        public IEnumerator TestMotionControllerClickEvents()
        {
            // Switch to motion controller
            var iss        = PlayModeTestUtilities.GetInputSimulationService();
            var oldSimMode = iss.ControllerSimulationMode;

            iss.ControllerSimulationMode = ControllerSimulationMode.MotionController;

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

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

            var testMotionController = new TestMotionController(Handedness.Right);

            yield return(testMotionController.Show(new Vector3(1, 0, 0)));

            yield return(testMotionController.Click());

            yield return(testMotionController.Hide());

            Assert.True(wasClicked);

            // Restore the input simulation profile
            iss.ControllerSimulationMode = oldSimMode;

            yield return(null);
        }
Exemplo n.º 2
0
        public IEnumerator TriggerButtonFarInteractionWithMotionController([ValueSource(nameof(PressableButtonsTestPrefabPaths))] string prefabFilename)
        {
            GameObject testButton = InstantiateDefaultPressableButton(prefabFilename);

            TestUtilities.PlayspaceToOriginLookingForward();

            Interactable interactableComponent = testButton.GetComponent <Interactable>();
            Button       buttonComponent       = testButton.GetComponent <Button>();

            Assert.IsTrue(interactableComponent != null || buttonComponent != null, "Depending on button type, there should be either an Interactable or a UnityUI Button on the control");

            var objectToMoveAndScale = testButton.transform;

            if (buttonComponent != null)
            {
                objectToMoveAndScale = testButton.transform.parent;
            }

            objectToMoveAndScale.position   += new Vector3(0f, 0.3f, 0.8f);
            objectToMoveAndScale.localScale *= 15f; // scale button up so it's easier to hit it with the far interaction pointer
            yield return(new WaitForFixedUpdate());

            yield return(null);

            bool buttonTriggered = false;

            var onClickEvent = (interactableComponent != null) ? interactableComponent.OnClick : buttonComponent.onClick;

            onClickEvent.AddListener(() =>
            {
                buttonTriggered = true;
            });

            // Switch to motion controller
            var iss            = PlayModeTestUtilities.GetInputSimulationService();
            var oldHandSimMode = iss.ControllerSimulationMode;

            iss.ControllerSimulationMode = ControllerSimulationMode.MotionController;
            TestMotionController motionController   = new TestMotionController(Handedness.Right);
            Vector3 initialmotionControllerPosition = new Vector3(0.05f, -0.05f, 0.3f); // orient hand so far interaction ray will hit button

            yield return(motionController.Show(initialmotionControllerPosition));

            yield return(motionController.Click());

            Assert.IsTrue(buttonTriggered, "Button did not get triggered with far interaction.");

            Object.Destroy(testButton);
            // Restore the input simulation profile
            iss.ControllerSimulationMode = oldHandSimMode;
            yield return(null);
        }
Exemplo n.º 3
0
        public IEnumerator TestMotionControllerToggleEvents()
        {
            // Switch to motion controller
            var iss        = PlayModeTestUtilities.GetInputSimulationService();
            var oldSimMode = iss.ControllerSimulationMode;

            iss.ControllerSimulationMode = ControllerSimulationMode.MotionController;

            var toggleReceiver = interactable.AddReceiver <InteractableOnToggleReceiver>();

            interactable.transform.position = Vector3.forward * 2f;
            interactable.NumOfDimensions    = 2;
            interactable.CanSelect          = true;
            interactable.CanDeselect        = true;
            bool didSelect   = false;
            bool didUnselect = false;

            toggleReceiver.OnSelect.AddListener(() => didSelect     = true);
            toggleReceiver.OnDeselect.AddListener(() => didUnselect = true);

            var testMotionController = new TestMotionController(Handedness.Right);

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

            yield return(testMotionController.Click());

            yield return(testMotionController.Click());

            yield return(testMotionController.Hide());

            Assert.True(didSelect, "Toggle select did not fire");
            Assert.True(didUnselect, "Toggle unselect did not fire");
            yield return(null);

            // Restore the input simulation profile
            iss.ControllerSimulationMode = oldSimMode;

            yield return(null);
        }