public IEnumerator TestTapToPlaceOnClickHead() { TestUtilities.PlayspaceToOriginLookingForward(); // Create a cube with Tap to Place attached and Head (default) as the TrackedTargetType var tapToPlaceObj = InstantiateTestSolver <TapToPlace>(); tapToPlaceObj.target.transform.position = Vector3.forward; TapToPlace tapToPlace = tapToPlaceObj.solver as TapToPlace; // Set hand position Vector3 handStartPosition = new Vector3(0, -0.1f, 0.6f); var leftHand = new TestHand(Handedness.Left); yield return(leftHand.Show(handStartPosition)); // Select Tap to Place Obj yield return(leftHand.Click()); // Make sure the object is being placed Assert.True(tapToPlace.IsBeingPlaced); // Move the playspace to simulate head movement MixedRealityPlayspace.PerformTransformation(p => { p.position = Vector3.left * 1.5f; }); yield return(new WaitForFixedUpdate()); yield return(null); // Make sure the target obj has followed the head Assert.AreEqual(CameraCache.Main.transform.position.x, tapToPlaceObj.target.transform.position.x, "The tap to place object position.x does not match the camera position.x"); // Tap to place has a 0.5 sec timer between clicks to make sure a double click does not get registered // We need to wait at least 0.5 secs until another click is called or tap to place will ignore the action yield return(new WaitForSeconds(0.5f)); // Click object to stop placement yield return(leftHand.Click()); // Make sure the object is not being placed after the click Assert.False(tapToPlace.IsBeingPlaced); // Move the playspace to simulate head movement again MixedRealityPlayspace.PerformTransformation(p => { p.position = Vector3.right; }); yield return(new WaitForFixedUpdate()); yield return(null); // Make sure the target obj is NOT following the head Assert.AreNotEqual(CameraCache.Main.transform.position.x, tapToPlaceObj.target.transform.position.x, "The tap to place object position.x matches camera position.x, when it should not"); }
public IEnumerator TestTapToPlaceOnClickControllerRay() { TestUtilities.PlayspaceToOriginLookingForward(); // Create a cube with Tap to Place attached var tapToPlaceObj = InstantiateTestSolver <TapToPlace>(); tapToPlaceObj.target.transform.position = Vector3.forward; TapToPlace tapToPlace = tapToPlaceObj.solver as TapToPlace; // Switch the TrackedTargetType to Controller Ray SolverHandler tapToPlaceSolverHandler = tapToPlaceObj.handler; tapToPlaceSolverHandler.TrackedTargetType = TrackedObjectType.ControllerRay; // Set hand position Vector3 handStartPosition = new Vector3(0, -0.1f, 0.6f); var leftHand = new TestHand(Handedness.Left); yield return(leftHand.Show(handStartPosition)); Vector3 initialObjPosition = tapToPlaceObj.target.transform.position; yield return(leftHand.Click()); // Make sure the object is being placed after selection Assert.True(tapToPlace.IsBeingPlaced); // Move hand, object should follow yield return(leftHand.Move(Vector3.forward)); yield return(leftHand.Move(Vector3.up)); // Make sure the object starting position is different from the current position Assert.True(initialObjPosition != tapToPlaceObj.target.transform.position); // Tap to place has a 0.5 sec timer between clicks to make sure a double click does not get registered // We need to wait at least 0.5 secs until another click is called or tap to place will ignore the action yield return(new WaitForSeconds(0.5f)); // Click to stop the placement yield return(leftHand.Click()); // Make sure the object is not being placed Assert.False(tapToPlace.IsBeingPlaced); // Get new position of the object after it is placed Vector3 newPosition = tapToPlaceObj.target.transform.position; // Move hand, the object should NOT move yield return(leftHand.Move(Vector3.back, 30)); Assert.True(newPosition == tapToPlaceObj.target.transform.position); }
public IEnumerator TestClickedEventConfiguration() { // Create an interactive cube InteractiveElement interactiveElement = CreateInteractiveCube(); yield return(null); // Add the clicked state InteractionState clicked = interactiveElement.AddNewState(clickedStateName); yield return(null); // Get the event configuration for the Clicked state var eventConfiguration = interactiveElement.GetStateEvents <ClickedEvents>(clickedStateName); bool onClicked = false; eventConfiguration.OnClicked.AddListener(() => { onClicked = true; }); // Create a new hand and initialize it with an object in focus var leftHand = new TestHand(Handedness.Left); // Show hand at starting position yield return(ShowHandWithObjectInFocus(leftHand)); // Click the hand to trigger far select events yield return(leftHand.Click()); Assert.True(onClicked); }
public IEnumerator TestSelectFarEventConfiguration() { // Create an interactive cube InteractiveElement interactiveElement = CreateInteractiveCube(); yield return(null); // Add the selectFar state InteractionState selectFar = interactiveElement.AddNewState(selectFarStateName); yield return(null); // Get the event configuration for the SelectFar state var eventConfiguration = interactiveElement.GetStateEvents <SelectFarEvents>(selectFarStateName); // Set global to true, this registers the IMixedRealityPointerHandler eventConfiguration.Global = true; bool onSelectDown = false; bool onSelectHold = false; bool onSelectClicked = false; bool onSelectUp = false; eventConfiguration.OnSelectDown.AddListener((eventData) => { onSelectDown = true; }); eventConfiguration.OnSelectHold.AddListener((eventData) => { onSelectHold = true; }); eventConfiguration.OnSelectClicked.AddListener((eventData) => { onSelectClicked = true; }); eventConfiguration.OnSelectUp.AddListener((eventData) => { onSelectUp = true; }); // Create a new hand and initialize it with an object in focus var leftHand = new TestHand(Handedness.Left); // Show hand at starting position yield return(ShowHandWithObjectInFocus(leftHand)); yield return(MoveHandOutOfFocus(leftHand)); // Click the hand to trigger far select events yield return(leftHand.Click()); Assert.True(onSelectDown); Assert.True(onSelectHold); Assert.True(onSelectClicked); Assert.True(onSelectUp); eventConfiguration.Global = false; yield return(leftHand.SetGesture(ArticulatedHandPose.GestureId.Pinch)); // Make sure the SelectFar state is not active after setting global to false without an object in focus Assert.AreEqual(0, selectFar.Value); }
public IEnumerator TestToggleEvents() { var iss = PlayModeTestUtilities.GetInputSimulationService(); var oldSimMode = iss.ControllerSimulationMode; iss.ControllerSimulationMode = ControllerSimulationMode.HandGestures; 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 testHand = new TestHand(Handedness.Right); yield return(testHand.Show(Vector3.forward)); CameraCache.Main.transform.LookAt(interactable.transform.position); yield return(testHand.SetGesture(ArticulatedHandPose.GestureId.Open)); yield return(testHand.Click()); yield return(testHand.Click()); yield return(testHand.Hide()); Assert.True(didSelect, "Toggle select did not fire"); Assert.True(didUnselect, "Toggle unselect did not fire"); iss.ControllerSimulationMode = oldSimMode; }
public IEnumerator TestPressableToggleHoloLens2() { var rightHand = new TestHand(Handedness.Right); Vector3 p2 = new Vector3(0.015f, 0f, 0.3f); Interactable interactable; Transform frontPlateTransform; InstantiatePressableButtonPrefab( new Vector3(0.0f, 0.1f, 0.4f), DefaultRotationToggle, PressableHoloLens2TogglePrefabPath, "CompressableButtonVisuals/FrontPlate", out interactable, out frontPlateTransform); Assert.True(interactable.IsEnabled); bool wasClicked = false; interactable.OnClick.AddListener(() => { wasClicked = true; }); // Get start position of the front plate before button is pressed Vector3 frontPlateStartPosition = frontPlateTransform.localPosition; yield return(rightHand.Show(p2)); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.IsTrue(interactable.HasFocus, "Interactable does not have focus when hand is pointing at it."); int numClicks = 3; for (int i = 0; i < numClicks; i++) { wasClicked = false; yield return(rightHand.Click()); // Wait for button animation to complete yield return(new WaitForSeconds(0.33f)); Assert.True(wasClicked, "Toggle button was not clicked"); Assert.AreEqual((i + 1) % 2, interactable.CurrentDimension, $"Toggle button is in incorrect toggle state on click {i}"); // Make sure the button depth is back at the starting position Assert.True(frontPlateTransform.localPosition == frontPlateStartPosition, "Toggle button front plate did not return to starting position."); } GameObject.Destroy(interactable.gameObject); }
public IEnumerator TestToggleEvents() { // Create an interactive cube InteractiveElement interactiveElement = CreateInteractiveCube(); yield return(null); interactiveElement.AddToggleStates(); yield return(null); // Get the event configuration for the ToggleOn state var eventConfigurationToggleOn = interactiveElement.GetStateEvents <ToggleOnEvents>(toggleOnStateName); // Get the event configuration for the ToggleOn state var eventConfigurationToggleOff = interactiveElement.GetStateEvents <ToggleOffEvents>(toggleOffStateName); bool onToggleOn = false; bool onToggleOff = false; eventConfigurationToggleOn.OnToggleOn.AddListener(() => { onToggleOn = true; }); eventConfigurationToggleOff.OnToggleOff.AddListener(() => { onToggleOff = true; }); interactiveElement.SetToggleStates(); yield return(null); // Make sure the toggle is on at the start Assert.True(onToggleOn); // Create a new hand and initialize it with an object in focus var leftHand = new TestHand(Handedness.Left); // Show hand at starting position yield return(ShowHandWithObjectInFocus(leftHand)); // Click the hand yield return(leftHand.Click()); Assert.True(onToggleOff); }