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); }
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); }
public IEnumerator TestMotionControllerPointerDirectionToCameraDirection() { var inputSystem = PlayModeTestUtilities.GetInputSystem(); // Switch to motion controller var iss = PlayModeTestUtilities.GetInputSimulationService(); var oldSimMode = iss.ControllerSimulationMode; iss.ControllerSimulationMode = ControllerSimulationMode.MotionController; // Raise the motion controller var rightMotionController = new TestMotionController(Handedness.Right); // Set initial position and show motion controller Vector3 initialPos = TestUtilities.PositionRelativeToPlayspace(new Vector3(0.01f, 0.1f, 0.5f)); yield return(rightMotionController.Show(initialPos)); // Return first motion controller that is right and source type controller var motionController = inputSystem.DetectedControllers.First(x => x.ControllerHandedness == Handedness.Right && x.InputSource.SourceType == InputSourceType.Controller); Assert.IsNotNull(motionController); // Get the line pointer from the motion controller var linePointer = motionController.InputSource.Pointers.OfType <ShellHandRayPointer>().First(); Assert.IsNotNull(linePointer); Vector3 linePointerOrigin = linePointer.Position; // Check that the line pointer origin is within half a centimeter of the initial position of the motion controller var distance = Vector3.Distance(initialPos, linePointerOrigin); Assert.LessOrEqual(distance, 0.005f); // Check that the angle between the line pointer ray and camera forward does not exceed 40 degrees float angle = Vector3.Angle(linePointer.Rays[0].Direction, CameraCache.Main.transform.forward); Assert.LessOrEqual(angle, 40.0f); // Restore the input simulation profile iss.ControllerSimulationMode = oldSimMode; yield return(null); }
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); }
public IEnumerator TestMotionControllerHoldEvents() { // Switch to motion controller var iss = PlayModeTestUtilities.GetInputSimulationService(); var oldSimMode = iss.ControllerSimulationMode; iss.ControllerSimulationMode = ControllerSimulationMode.MotionController; // Hold var holdReceiver = interactable.AddReceiver <InteractableOnHoldReceiver>(); bool didHold = false; holdReceiver.OnHold.AddListener(() => didHold = true); var testMotionController = new TestMotionController(Handedness.Right); yield return(testMotionController.Show(new Vector3(1, 0, 0))); SimulatedMotionControllerButtonState selectButtonState = new SimulatedMotionControllerButtonState() { IsSelecting = true }; yield return(testMotionController.SetState(selectButtonState)); yield return(new WaitForSeconds(holdReceiver.HoldTime)); yield return(testMotionController.Hide()); Assert.True(didHold, "Did not receive hold event"); GameObject.Destroy(cube); yield return(null); // Restore the input simulation profile iss.ControllerSimulationMode = oldSimMode; yield return(null); }
public IEnumerator ScaleViaMotionControllerInteraction() { var bbox = InstantiateSceneAndDefaultBbox(); yield return(null); yield return(null); var bounds = bbox.GetComponent <BoxCollider>().bounds; var startCenter = new Vector3(0, 0, 1.5f); var startSize = new Vector3(.5f, .5f, .5f); TestUtilities.AssertAboutEqual(bounds.center, startCenter, "bbox incorrect center at start"); TestUtilities.AssertAboutEqual(bounds.size, startSize, "bbox incorrect size at start"); // Switch to motion controller var iss = PlayModeTestUtilities.GetInputSimulationService(); var oldSimMode = iss.ControllerSimulationMode; iss.ControllerSimulationMode = ControllerSimulationMode.MotionController; CameraCache.Main.transform.LookAt(bbox.ScaleCorners[3].transform); var startPos = CameraCache.Main.transform.TransformPoint(new Vector3(0.21f, -0.35f, 0f)); TestMotionController rightMotionController = new TestMotionController(Handedness.Right); yield return(rightMotionController.Show(startPos)); SimulatedMotionControllerButtonState selectButtonState = new SimulatedMotionControllerButtonState { IsSelecting = true }; yield return(rightMotionController.SetState(selectButtonState)); yield return(null); var delta = new Vector3(0.1f, 0.1f, 0f); yield return(rightMotionController.Move(delta)); yield return(null); SimulatedMotionControllerButtonState defaultButtonState = new SimulatedMotionControllerButtonState(); yield return(rightMotionController.SetState(defaultButtonState)); yield return(null); var endBounds = bbox.GetComponent <BoxCollider>().bounds; TestUtilities.AssertAboutEqual(endBounds.center, new Vector3(0.033f, 0.033f, 1.467f), "endBounds incorrect center", 0.02f); TestUtilities.AssertAboutEqual(endBounds.size, Vector3.one * .561f, "endBounds incorrect size", 0.02f); Object.Destroy(bbox.gameObject); // Wait for a frame to give Unity a change to actually destroy the object yield return(null); // Restore the input simulation profile iss.ControllerSimulationMode = oldSimMode; yield return(null); }