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