public void TearDown() { PlayModeTestUtilities.TearDown(); GameObject.Destroy(asyncCoroutineRunner.gameObject); }
public IEnumerator TearDown() { PlayModeTestUtilities.TearDown(); yield return(null); }
public IEnumerator NearInteractionTouchableSetTouchableCollider() { GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.position = new Vector3(0, 0, 2f); cube.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f); var rightHand = new TestHand(Handedness.Right); yield return(rightHand.Show(new Vector3(0, 0, 1.5f))); // Add NearInteractionTouchable var nearIT = cube.AddComponent <NearInteractionTouchable>(); // Create new gameObject for testing a new BoxCollider GameObject cube2 = GameObject.CreatePrimitive(PrimitiveType.Cube); cube2.transform.position = new Vector3(-1f, 0, 2f); cube2.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); using (var catcher = CreateTouchEventCatcher(nearIT)) { // Touch started and completed when entering and exiting the collider yield return(rightHand.Move(new Vector3(0, 0, 0.4f))); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.AreEqual(1, catcher.EventsStarted); Assert.AreEqual(0, catcher.EventsCompleted); yield return(rightHand.Move(new Vector3(0, 0, -0.4f))); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.AreEqual(1, catcher.EventsStarted); Assert.AreEqual(1, catcher.EventsCompleted); // Set new touchableCollider bounds // Change touchableCollider to a new BoxCollider with a different size from another object BoxCollider newBoxCollider = cube2.GetComponent <BoxCollider>(); newBoxCollider.size = new Vector3(4, 2, 1f); nearIT.SetTouchableCollider(newBoxCollider); // Move hand to the side yield return(rightHand.Move(new Vector3(-0.4f, 0, 0))); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.AreEqual(1, catcher.EventsStarted); Assert.AreEqual(1, catcher.EventsCompleted); // Move hand forward, on touch yield return(rightHand.Move(new Vector3(0, 0, 0.5f))); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.AreEqual(2, catcher.EventsStarted); // Move the hand back, on touch exit yield return(rightHand.Move(new Vector3(0, 0, -0.5f))); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.AreEqual(2, catcher.EventsCompleted); } }
public void Setup() { PlayModeTestUtilities.Setup(); TestUtilities.PlayspaceToOriginLookingForward(); }
public IEnumerator BBoxHandlerUI() { const int numSteps = 2; var bbox = InstantiateSceneAndDefaultBbox(); bbox.ShowRotationHandleForX = true; bbox.ShowRotationHandleForY = true; bbox.ShowRotationHandleForZ = true; bbox.ShowScaleHandles = true; bbox.ProximityEffectActive = true; bbox.ScaleHandleSize = 0.1f; bbox.RotationHandleSize = 0.1f; bbox.FarScale = 1.0f; bbox.MediumScale = 1.5f; bbox.CloseScale = 1.5f; yield return(null); var bounds = bbox.GetComponent <BoxCollider>().bounds; Assert.AreEqual(new Vector3(0, 0, 1.5f), bounds.center); Assert.AreEqual(new Vector3(.5f, .5f, .5f), bounds.size); var inputSimulationService = PlayModeTestUtilities.GetInputSimulationService(); // Definining the edge and corner handlers that will be used Debug.Log(bbox.transform.Find("rigRoot/midpoint_0").GetChild(0)); var originalCornerHandlerScale = bbox.transform.Find("rigRoot/corner_0/visualsScale/visuals").transform.localScale; var cornerHandlerPosition = bbox.transform.Find("rigRoot/corner_0").transform.position; var originalEdgeHandlerScale = bbox.transform.Find("rigRoot/midpoint_0/Sphere").transform.localScale; var edgeHandlerPosition = bbox.transform.Find("rigRoot/midpoint_0").transform.position; // Wait for the scaling/unscaling animation to finish yield return(new WaitForSeconds(0.2f)); // Move the hand to a handler on the corner TestHand rightHand = new TestHand(Handedness.Right); yield return(rightHand.Show(new Vector3(0, 0, 0.5f))); var delta = new Vector3(0.1f, 0.1f, 0f); yield return(rightHand.MoveTo(cornerHandlerPosition, numSteps)); // Wait for the scaling/unscaling animation to finish yield return(new WaitForSeconds(0.4f)); TestUtilities.AssertAboutEqual(bbox.transform.Find("rigRoot/midpoint_0/Sphere").transform.localScale, originalEdgeHandlerScale, "The edge handler changed mistakingly"); TestUtilities.AssertAboutEqual(bbox.transform.Find("rigRoot/corner_0/visualsScale/visuals").transform.localScale.normalized, originalCornerHandlerScale.normalized, "The corner handler scale has changed"); Assert.AreApproximatelyEqual(bbox.transform.Find("rigRoot/corner_0/visualsScale/visuals").transform.localScale.x / originalCornerHandlerScale.x, bbox.MediumScale, 0.1f, "The corner handler did not grow when a pointer was near it"); // Move the hand to a handler on the edge yield return(rightHand.MoveTo(edgeHandlerPosition, numSteps)); // Wait for the scaling/unscaling animation to finish yield return(new WaitForSeconds(0.4f)); TestUtilities.AssertAboutEqual(bbox.transform.Find("rigRoot/corner_0/visualsScale/visuals").transform.localScale, originalCornerHandlerScale, "The corner handler changed mistakingly"); TestUtilities.AssertAboutEqual(bbox.transform.Find("rigRoot/midpoint_0/Sphere").transform.localScale.normalized, originalEdgeHandlerScale.normalized, "The edge handler scale has changed"); Assert.AreApproximatelyEqual(bbox.transform.Find("rigRoot/midpoint_0/Sphere").transform.localScale.x / originalEdgeHandlerScale.x, bbox.MediumScale, 0.1f, "The edge handler did not grow when a pointer was near it"); GameObject.Destroy(bbox.gameObject); // Wait for a frame to give Unity a change to actually destroy the object yield return(null); }
public IEnumerator TearDown() { GameObject.Destroy(cube); PlayModeTestUtilities.TearDown(); yield return(null); }
public IEnumerator SetUp() { PlayModeTestUtilities.Setup(); yield return(null); }
public IEnumerator Setup() { PlayModeTestUtilities.Setup(); TestUtilities.PlayspaceToOriginLookingForward(); yield return(null); }
public IEnumerator TestInputActions() { Interactable interactable; Transform translateTargetObject; AssembleInteractableButton( out interactable, out translateTargetObject); interactable.transform.position = new Vector3(0.0f, 0.0f, 0.5f); interactable.transform.eulerAngles = new Vector3(-90f, 0f, 0f); // Subscribe to interactable's on click and on press receiver so we know the click went through bool wasClicked = false; interactable.OnClick.AddListener(() => { wasClicked = true; }); var pressReceiver = interactable.AddReceiver <InteractableOnPressReceiver>(); bool wasPressed = false; pressReceiver.OnPress.AddListener(() => { wasPressed = true; Debug.Log("pressReciever wasPressed true"); }); bool wasReleased = false; pressReceiver.OnRelease.AddListener(() => { wasReleased = true; Debug.Log("pressReciever wasReleased true"); }); Vector3 targetStartPosition = translateTargetObject.localPosition; yield return(null); // // Test Select Input Action // // Find an input source to associate with the input event (doesn't matter which one) IMixedRealityInputSource defaultInputSource = CoreServices.InputSystem.DetectedInputSources.FirstOrDefault(); Assert.NotNull(defaultInputSource, "At least one input source must be present for this test to work."); yield return(RunGlobalClick(defaultInputSource, interactable.InputAction, targetStartPosition, translateTargetObject)); Assert.True(wasClicked, "Interactable was not clicked."); Assert.True(wasPressed, "interactable not pressed"); Assert.True(wasReleased, "interactable not released"); Assert.AreEqual(targetStartPosition, translateTargetObject.localPosition, "Transform target object was not translated back by action."); // // Test Menu Input Action // // Find the menu action from the input system profile MixedRealityInputAction menuAction = CoreServices.InputSystem.InputSystemProfile.InputActionsProfile.InputActions.Where(m => m.Description == "Menu").FirstOrDefault(); Assert.NotNull(menuAction.Description, "Couldn't find menu input action in input system profile."); // Set the interactable to respond to a 'menu' input action interactable.InputAction = menuAction; // Reset state tracking wasClicked = wasPressed = wasReleased = false; yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); yield return(RunGlobalClick(defaultInputSource, menuAction, targetStartPosition, translateTargetObject)); Assert.True(wasClicked, "Interactable was not clicked."); Assert.True(wasPressed, "interactable not pressed"); Assert.True(wasReleased, "interactable not released"); Assert.AreEqual(targetStartPosition, translateTargetObject.localPosition, "Transform target object was not translated back by action."); //Cleanup GameObject.Destroy(interactable.gameObject); }
public TestHand(Handedness handedness) { this.handedness = handedness; simulationService = PlayModeTestUtilities.GetInputSimulationService(); }
public IEnumerator TestDialogPrefabResults() { TestHand handRight = new TestHand(Handedness.Right); int handsteps = 80; // Testing near interactions handRight.Show(Vector3.zero); InstantiateFromPrefab("Test Dialog", "This is an example dialog", DialogButtonType.OK, true); // Wait for the dialog to move to a stable position yield return(new WaitForSeconds(DialogStabilizationTime)); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.IsTrue(dialogComponent.State == DialogState.WaitingForInput); yield return(handRight.Move(new Vector3(0.0f, -0.1f, 1.0f), handsteps)); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.AreEqual(dialogResult, DialogButtonType.OK); Assert.AreEqual(dialogComponent.State, DialogState.Closed); GameObject.Destroy(dialogGameObject); GameObject.Destroy(dialogComponent); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); // The dialog only supports displaying up to two options yield return(handRight.MoveTo(Vector3.zero)); InstantiateFromPrefab("Test Dialog", "This is an example dialog", DialogButtonType.Yes | DialogButtonType.No, true); // Wait for the dialog to move to a stable position yield return(new WaitForSeconds(DialogStabilizationTime)); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.IsTrue(dialogComponent.State == DialogState.WaitingForInput); yield return(handRight.Move(new Vector3(0.1f, -0.1f, 1.0f), handsteps)); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.AreEqual(dialogResult, DialogButtonType.No); Assert.AreEqual(dialogComponent.State, DialogState.Closed); GameObject.Destroy(dialogGameObject); GameObject.Destroy(dialogComponent); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); // Testing far interactions // The dialog only supports displaying up to two options yield return(handRight.MoveTo(Vector3.zero)); InstantiateFromPrefab("Test Dialog", "This is an example dialog", DialogButtonType.Yes | DialogButtonType.No, false); // Wait for the dialog to move to a stable position yield return(new WaitForSeconds(DialogStabilizationTime)); Assert.IsTrue(dialogComponent.State == DialogState.WaitingForInput); // moving the hand to an appropriate position to click on the dialog yield return(handRight.Move(new Vector3(-0.1f, -0.2f, 0.7f), handsteps)); yield return(handRight.SetGesture(ArticulatedHandPose.GestureId.Pinch)); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); yield return(handRight.SetGesture(ArticulatedHandPose.GestureId.Open)); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.AreEqual(dialogResult, DialogButtonType.Yes); Assert.AreEqual(dialogComponent.State, DialogState.Closed); GameObject.Destroy(dialogGameObject); GameObject.Destroy(dialogComponent); }
public IEnumerator TestHandInputOnRuntimeAssembled() { // Load interactable Interactable interactable; Transform translateTargetObject; AssembleInteractableButton( out interactable, out translateTargetObject); interactable.transform.position = new Vector3(0.025f, 0.05f, 0.65f); interactable.transform.eulerAngles = new Vector3(-90f, 0f, 0f); // Subscribe to interactable's on click so we know the click went through bool wasClicked = false; interactable.OnClick.AddListener(() => { wasClicked = true; }); Vector3 targetStartPosition = translateTargetObject.transform.localPosition; yield return(null); // Add a touchable and configure for touch events NearInteractionTouchable touchable = interactable.gameObject.AddComponent <NearInteractionTouchable>(); touchable.EventsToReceive = TouchableEventType.Touch; touchable.SetBounds(Vector2.one); touchable.SetLocalForward(Vector3.up); touchable.SetLocalUp(Vector3.forward); touchable.SetLocalCenter(Vector3.up * 2.75f); // Add a touch handler and link touch started / touch completed events TouchHandler touchHandler = interactable.gameObject.AddComponent <TouchHandler>(); touchHandler.OnTouchStarted.AddListener((HandTrackingInputEventData e) => interactable.SetInputDown()); touchHandler.OnTouchCompleted.AddListener((HandTrackingInputEventData e) => interactable.SetInputUp()); // Move the hand forward to intersect the interactable var inputSimulationService = PlayModeTestUtilities.GetInputSimulationService(); int numSteps = 32; Vector3 p1 = Vector3.zero; Vector3 p2 = new Vector3(0.05f, 0f, 0.51f); Vector3 p3 = Vector3.zero; yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSimulationService)); yield return(PlayModeTestUtilities.MoveHandFromTo(p1, p2, numSteps, ArticulatedHandPose.GestureId.Poke, Handedness.Right, inputSimulationService)); yield return(CheckButtonTranslation(targetStartPosition, translateTargetObject)); // Move the hand back yield return(PlayModeTestUtilities.MoveHandFromTo(p2, p3, numSteps, ArticulatedHandPose.GestureId.Poke, Handedness.Right, inputSimulationService)); yield return(PlayModeTestUtilities.HideHand(Handedness.Right, inputSimulationService)); yield return(new WaitForSeconds(ButtonReleaseAnimationDelay)); Assert.True(wasClicked, "Interactable was not clicked."); //Cleanup GameObject.Destroy(interactable.gameObject); }
public IEnumerator TearDown() { PlayModeTestUtilities.TearDown(); GameObject.Destroy(asyncCoroutineRunner.gameObject); yield return(null); }
public IEnumerator Setup() { PlayModeTestUtilities.Setup(); asyncCoroutineRunner = new GameObject("AsyncCoroutineRunner").AddComponent <AsyncCoroutineRunner>(); yield return(null); }
public IEnumerator TestHandlerBasedEventRegistration() { // Need to remove cursors and other global event handlers yield return(PlayModeTestUtilities.SetupMrtkWithoutGlobalInputHandlers()); BaseEventSystem inputSystem = (BaseEventSystem)CoreServices.InputSystem; var object1 = new GameObject("Object"); // These 2 handlers are independent // 1st is Pointer + Speech // 2nd is Speech only var handlerBasedListener1 = object1.AddComponent <TestInputGlobalListenerHandlerBasedAllHandlers>(); var handlerBasedListener2 = object1.AddComponent <TestInputGlobalListenerHandlerBasedSpeechHandler>(); yield return(null); // No event listener registration in this test CollectionAssert.IsEmpty(inputSystem.EventListeners, "Event listener for old event system API shouldn't be registered"); CollectionAssert.AreEquivalent( new List <System.Type> { typeof(IMixedRealityPointerHandler), typeof(IMixedRealitySpeechHandler), typeof(IMixedRealityBaseInputHandler) }, inputSystem.EventHandlersByType.Keys, "Input event system doesn't contain expected event handler types."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener1) }, inputSystem.EventHandlersByType[typeof(IMixedRealityPointerHandler)], "Input event system doesn't contain expected IMixedRealityPointerHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener1), new Handle(handlerBasedListener2) }, inputSystem.EventHandlersByType[typeof(IMixedRealitySpeechHandler)], "Input event system doesn't contain expected IMixedRealitySpeechHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener1), new Handle(handlerBasedListener2) }, inputSystem.EventHandlersByType[typeof(IMixedRealityBaseInputHandler)], "Input event system doesn't contain expected IMixedRealityBaseInputHandler handlers."); // Disabling one component doesn't influence another one. handlerBasedListener1.enabled = false; CollectionAssert.AreEquivalent( new List <System.Type> { typeof(IMixedRealitySpeechHandler), typeof(IMixedRealityBaseInputHandler) }, inputSystem.EventHandlersByType.Keys, "Input event system doesn't contain expected event handler types."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener2) }, inputSystem.EventHandlersByType[typeof(IMixedRealitySpeechHandler)], "Input event system doesn't contain expected IMixedRealitySpeechHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener2) }, inputSystem.EventHandlersByType[typeof(IMixedRealityBaseInputHandler)], "Input event system doesn't contain expected IMixedRealityBaseInputHandler handlers."); Object.Destroy(object1); yield return(null); }
public IEnumerator TestVoiceInputOnPrefab() { // Load interactable prefab Interactable interactable; Transform translateTargetObject; InstantiatePressableButtonPrefab( new Vector3(0.0f, 0.0f, 0.5f), DefaultRotation, DefaultInteractablePrefabAssetPath, "Cylinder", out interactable, out translateTargetObject); // Subscribe to interactable's on click so we know the click went through bool wasClicked = false; interactable.OnClick.AddListener(() => { wasClicked = true; }); Vector3 targetStartPosition = translateTargetObject.localPosition; // Set up its voice command interactable.VoiceCommand = "Select"; interactable.VoiceRequiresFocus = false; // Find an input source to associate with the input event (doesn't matter which one) IMixedRealityInputSource defaultInputSource = CoreServices.InputSystem.DetectedInputSources.FirstOrDefault(); Assert.NotNull(defaultInputSource, "At least one input source must be present for this test to work."); // // Test speech when disabled // interactable.IsEnabled = false; yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); yield return(FireSpeechCommand(interactable.VoiceCommand, interactable.InputAction, defaultInputSource)); yield return(CheckButtonTranslation(targetStartPosition, translateTargetObject, false)); Assert.False(wasClicked, "Interactable was clicked."); Assert.False(interactable.IsVisited, "Interactable was visited."); // // Test speech when enabled // interactable.IsEnabled = true; yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); yield return(FireSpeechCommand(interactable.VoiceCommand, interactable.InputAction, defaultInputSource)); yield return(CheckButtonTranslation(targetStartPosition, translateTargetObject)); Assert.True(wasClicked, "Interactable was not clicked."); Assert.True(interactable.IsVisited, "Interactable was not visited."); //Cleanup GameObject.Destroy(interactable.gameObject); }
public IEnumerator TestObjectBasedEventRegistration() { // Need to remove cursors and other global event handlers yield return(PlayModeTestUtilities.SetupMrtkWithoutGlobalInputHandlers()); BaseEventSystem inputSystem = (BaseEventSystem)CoreServices.InputSystem; var object1 = new GameObject("Object"); // Second handler weirdly depends on the first one due to event registration working on the entire object var objectBasedListener = object1.AddComponent <TestInputGlobalListenerObjectBased>(); var handlerBasedListener = object1.AddComponent <TestInputGlobalListenerHandlerBasedSpeechHandler>(); yield return(null); LogAssert.Expect(LogType.Error, new Regex("Detected simultaneous usage of IMixedRealityEventSystem.Register and IMixedRealityEventSystem.RegisterHandler")); // Event listener collection is filled for backward compatibility CollectionAssert.AreEquivalent( new List <GameObject> { objectBasedListener.gameObject }, inputSystem.EventListeners, "Event listener for old event system API hasn't been registered correctly."); CollectionAssert.AreEquivalent( new List <System.Type> { typeof(IMixedRealitySpeechHandler), typeof(IMixedRealityBaseInputHandler) }, inputSystem.EventHandlersByType.Keys, "Input event system doesn't contain expected event handler types."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener, true) }, inputSystem.EventHandlersByType[typeof(IMixedRealitySpeechHandler)], "Input event system doesn't contain expected IMixedRealitySpeechHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener, true) }, inputSystem.EventHandlersByType[typeof(IMixedRealityBaseInputHandler)], "Input event system doesn't contain expected IMixedRealityBaseInputHandler handlers."); // Make sure that disabling global listener doesn't remove the new API one. objectBasedListener.enabled = false; CollectionAssert.IsEmpty(inputSystem.EventListeners, "Event listener for old event system API shouldn't be registered"); CollectionAssert.AreEquivalent( new List <System.Type> { typeof(IMixedRealitySpeechHandler), typeof(IMixedRealityBaseInputHandler) }, inputSystem.EventHandlersByType.Keys, "Input event system doesn't contain expected event handler types."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener, false) }, inputSystem.EventHandlersByType[typeof(IMixedRealitySpeechHandler)], "Input event system doesn't contain expected IMixedRealitySpeechHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener, false) }, inputSystem.EventHandlersByType[typeof(IMixedRealityBaseInputHandler)], "Input event system doesn't contain expected IMixedRealityBaseInputHandler handlers."); handlerBasedListener.enabled = false; CollectionAssert.IsEmpty(inputSystem.EventHandlersByType, "Input event system contains unexpected event handlers."); Object.Destroy(object1); yield return(null); }
public IEnumerator TestButtonStateResetWhenFocusLostAfterPinch() { Interactable interactable; Transform interactableTransform; InstantiatePressableButtonPrefab( new Vector3(0.0f, 0.1f, 0.4f), DefaultRotationToggle, PressableHoloLens2PrefabPath, "CompressableButtonVisuals/FrontPlate", out interactable, out interactableTransform); Assert.True(interactable.IsEnabled); var rightHand = new TestHand(Handedness.Right); Vector3 focusPosition = new Vector3(0.015f, 0.015f, 0.3f); Vector3 releaseDelta = new Vector3(0.05f, 0, 0); // Focus the hand on the Button using the far ray pointer yield return(rightHand.Show(focusPosition)); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.True(interactable.HasFocus); Assert.False(interactable.HasPress); Assert.False(interactable.HasGesture); Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Focus, "Interactable State is not Focus"); // While keeping focus on the Button, engage the pinch gesture yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Pinch)); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.True(interactable.HasFocus); Assert.True(interactable.HasPress); Assert.False(interactable.HasGesture); Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Pressed, "Interactable State is not Pressed"); // Move Hand to remove focus. Button should go to Default State yield return(rightHand.Move(releaseDelta)); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.False(interactable.HasFocus); Assert.False(interactable.HasPress); Assert.False(interactable.HasGesture); Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Default, "Interactable State is not Default"); // Open hand. Button should stay on Default State yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Open)); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.False(interactable.HasFocus); Assert.False(interactable.HasPress); Assert.False(interactable.HasGesture); Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Default, "Interactable State is not Default"); // Move Hand back to Initial position and Pinch. Button should go to Pressed State yield return(rightHand.Move(-releaseDelta)); yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Pinch)); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.True(interactable.HasFocus); Assert.True(interactable.HasPress); Assert.False(interactable.HasGesture); Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Pressed, "Interactable State is not Pressed"); // Open Hand. Button should go to Focus State yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Open)); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); Assert.True(interactable.HasFocus); Assert.False(interactable.HasPress); Assert.False(interactable.HasGesture); Assert.True(interactable.StateManager.CurrentState().Index == (int)InteractableStates.InteractableStateEnum.Focus, "Interactable State is not Focus"); GameObject.Destroy(interactable.gameObject); }
public void Setup() { PlayModeTestUtilities.Setup(); PlayModeTestUtilities.PushHandSimulationProfile(); TestUtilities.PlayspaceToOriginLookingForward(); }
public IEnumerator GestureCursorState() { var inputSystem = PlayModeTestUtilities.GetInputSystem(); var iss = PlayModeTestUtilities.GetInputSimulationService(); var oldIsp = iss.InputSimulationProfile; var isp = ScriptableObject.CreateInstance <MixedRealityInputSimulationProfile>(); isp.HandSimulationMode = HandSimulationMode.Gestures; iss.InputSimulationProfile = isp; Vector3 underPointerPos = new Vector3(0, 0, 2); Vector3 abovePointerPos = new Vector3(0, -2, 2); var rightHand = new TestHand(Handedness.Right); var leftHand = new TestHand(Handedness.Left); // No hands, pointer not on cube, hand open cube.transform.localPosition = abovePointerPos; yield return(new WaitForFixedUpdate()); yield return(null); VerifyCursorState(inputSystem.GazeProvider.GazeCursor, CursorStateEnum.Observe); // No hands, pointer on cube, hand open cube.transform.localPosition = underPointerPos; yield return(new WaitForFixedUpdate()); yield return(null); VerifyCursorState(inputSystem.GazeProvider.GazeCursor, CursorStateEnum.ObserveHover); // Right hand, pointer not on cube, hand open cube.transform.localPosition = abovePointerPos; yield return(new WaitForFixedUpdate()); yield return(rightHand.Show(Vector3.zero)); VerifyCursorState(inputSystem.GazeProvider.GazeCursor, CursorStateEnum.Interact); // Both hands, pointer not on cube, hand open yield return(leftHand.Show(Vector3.zero)); VerifyCursorState(inputSystem.GazeProvider.GazeCursor, CursorStateEnum.Interact); // Left hand, pointer not on cube, hand open yield return(rightHand.Hide()); VerifyCursorState(inputSystem.GazeProvider.GazeCursor, CursorStateEnum.Interact); // Left hand, pointer on cube, hand open cube.transform.localPosition = underPointerPos; yield return(new WaitForFixedUpdate()); yield return(null); VerifyCursorState(inputSystem.GazeProvider.GazeCursor, CursorStateEnum.InteractHover); // Both hands, pointer on cube, hand open yield return(rightHand.Show(Vector3.zero)); VerifyCursorState(inputSystem.GazeProvider.GazeCursor, CursorStateEnum.InteractHover); // Right hand, pointer on cube, hand open yield return(leftHand.Hide()); VerifyCursorState(inputSystem.GazeProvider.GazeCursor, CursorStateEnum.InteractHover); // Right hand, pointer on cube, hand pinched yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Pinch)); VerifyCursorState(inputSystem.GazeProvider.GazeCursor, CursorStateEnum.Select); yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Open)); // Left hand, pointer on cube, hand pinched yield return(rightHand.Hide()); yield return(leftHand.Show(Vector3.zero)); yield return(leftHand.SetGesture(ArticulatedHandPose.GestureId.Pinch)); VerifyCursorState(inputSystem.GazeProvider.GazeCursor, CursorStateEnum.Select); // Both hands, pointer on cube, left pinched & right open yield return(rightHand.Show(Vector3.zero)); yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Open)); VerifyCursorState(inputSystem.GazeProvider.GazeCursor, CursorStateEnum.Select); // Both hands, pointer on cube, both pinched yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Pinch)); VerifyCursorState(inputSystem.GazeProvider.GazeCursor, CursorStateEnum.Select); // Both hands, pointer on cube, right pinched & left open yield return(leftHand.SetGesture(ArticulatedHandPose.GestureId.Open)); VerifyCursorState(inputSystem.GazeProvider.GazeCursor, CursorStateEnum.Select); // Restore the input simulation profile iss.InputSimulationProfile = oldIsp; yield return(null); }
public void TearDown() { GameObject.Destroy(cube); PlayModeTestUtilities.TearDown(); }
public IEnumerator CursorContextMove() { var inputSystem = PlayModeTestUtilities.GetInputSystem(); // The cube needs to be moved from under the gaze cursor before we add the manipulation handler. // Because the cube is under the gaze cursor from the beginning, it gets a focus gained event // in Setup(). When we show the right hand, we get a focus lost event from the gaze pointer. // This messes with the CursorContextManipulationHandler hoverCount, as it decrements without // ever having incremented. To avoid this, we move the cube out of focus before we add the // ManipulationHandler and CursorContextManipulationHandler. cube.transform.localPosition = new Vector3(0, -2, 2); yield return(new WaitForFixedUpdate()); yield return(null); cube.AddComponent <ManipulationHandler>(); var temp = cube.AddComponent <CursorContextManipulationHandler>(); yield return(new WaitForFixedUpdate()); yield return(null); // Move cube back to original postion (described above) cube.transform.localPosition = new Vector3(0, 0, 2); yield return(new WaitForFixedUpdate()); yield return(null); // Show right hand on object var rightHand = new TestHand(Handedness.Right); Vector3 rightPos = new Vector3(0.05f, 0, 1.5f); yield return(rightHand.Show(rightPos)); yield return(new WaitForFixedUpdate()); yield return(null); VerifyCursorContextFromPointers(inputSystem.FocusProvider.GetPointers <ShellHandRayPointer>(), CursorContextEnum.None); // Pinch right hand yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Pinch)); yield return(new WaitForFixedUpdate()); yield return(null); VerifyCursorContextFromPointers(inputSystem.FocusProvider.GetPointers <ShellHandRayPointer>(), CursorContextEnum.MoveCross); // Show left hand on object var leftHand = new TestHand(Handedness.Left); Vector3 leftPos = new Vector3(-0.05f, 0, 1.5f); yield return(rightHand.Hide()); yield return(leftHand.Show(leftPos)); yield return(new WaitForFixedUpdate()); yield return(null); VerifyCursorContextFromPointers(inputSystem.FocusProvider.GetPointers <ShellHandRayPointer>(), CursorContextEnum.None); // Pinch left hand yield return(leftHand.SetGesture(ArticulatedHandPose.GestureId.Pinch)); yield return(new WaitForFixedUpdate()); yield return(null); VerifyCursorContextFromPointers(inputSystem.FocusProvider.GetPointers <ShellHandRayPointer>(), CursorContextEnum.MoveCross); // Show both hands on object yield return(rightHand.SetGesture(ArticulatedHandPose.GestureId.Open)); yield return(rightHand.Show(rightPos)); yield return(leftHand.SetGesture(ArticulatedHandPose.GestureId.Open)); yield return(new WaitForFixedUpdate()); yield return(null); VerifyCursorContextFromPointers(inputSystem.FocusProvider.GetPointers <ShellHandRayPointer>(), CursorContextEnum.MoveCross); Object.Destroy(cube.GetComponent <ManipulationHandler>()); Object.Destroy(cube.GetComponent <CursorContextManipulationHandler>()); }
public void TearDown() { PlayModeTestUtilities.TearDown(); }
public IEnumerator CursorContextScaleRotate() { var inputSystem = PlayModeTestUtilities.GetInputSystem(); var empty = new GameObject(); var info = cube.AddComponent <CursorContextInfo>(); info.ObjectCenter = empty.transform; // Show hand on object var hand = new TestHand(Handedness.Right); Vector3 handPos = new Vector3(0.05f, 0, 1.5f); yield return(hand.Show(handPos)); VerifyCursorContextFromPointers(inputSystem.FocusProvider.GetPointers <ShellHandRayPointer>(), CursorContextEnum.None); // rotate, center north info.CurrentCursorAction = CursorContextInfo.CursorAction.Rotate; empty.transform.SetPositionAndRotation(cube.transform.position + Vector3.up, Quaternion.identity); yield return(new WaitForFixedUpdate()); yield return(null); VerifyCursorContextFromPointers(inputSystem.FocusProvider.GetPointers <ShellHandRayPointer>(), CursorContextEnum.RotateNorthSouth); // rotate, center east empty.transform.SetPositionAndRotation(cube.transform.position + Vector3.right, Quaternion.identity); yield return(new WaitForFixedUpdate()); yield return(null); VerifyCursorContextFromPointers(inputSystem.FocusProvider.GetPointers <ShellHandRayPointer>(), CursorContextEnum.RotateEastWest); // scale, center northeast info.CurrentCursorAction = CursorContextInfo.CursorAction.Scale; empty.transform.SetPositionAndRotation(cube.transform.position + Vector3.up + Vector3.right, Quaternion.identity); yield return(new WaitForFixedUpdate()); yield return(null); VerifyCursorContextFromPointers(inputSystem.FocusProvider.GetPointers <ShellHandRayPointer>(), CursorContextEnum.MoveNortheastSouthwest); // scale, center southeast empty.transform.SetPositionAndRotation(cube.transform.position + Vector3.down + Vector3.right, Quaternion.identity); yield return(new WaitForFixedUpdate()); yield return(null); VerifyCursorContextFromPointers(inputSystem.FocusProvider.GetPointers <ShellHandRayPointer>(), CursorContextEnum.MoveNorthwestSoutheast); // scale, center northwest empty.transform.SetPositionAndRotation(cube.transform.position + Vector3.up + Vector3.left, Quaternion.identity); yield return(new WaitForFixedUpdate()); yield return(null); VerifyCursorContextFromPointers(inputSystem.FocusProvider.GetPointers <ShellHandRayPointer>(), CursorContextEnum.MoveNorthwestSoutheast); // scale, center southwest empty.transform.SetPositionAndRotation(cube.transform.position + Vector3.down + Vector3.left, Quaternion.identity); yield return(new WaitForFixedUpdate()); yield return(null); VerifyCursorContextFromPointers(inputSystem.FocusProvider.GetPointers <ShellHandRayPointer>(), CursorContextEnum.MoveNortheastSouthwest); Object.Destroy(empty); Object.Destroy(info); }
public void ShutdownMrtk() { PlayModeTestUtilities.TearDown(); }
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); }
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)); }
public IEnumerator Setup() { PlayModeTestUtilities.Setup(); TestUtilities.PlayspaceToArbitraryPose(); yield return(null); }
public void Setup() { PlayModeTestUtilities.Setup(); }
public void Setup() { PlayModeTestUtilities.Setup(); asyncCoroutineRunner = new GameObject("AsyncCoroutineRunner").AddComponent <AsyncCoroutineRunner>(); }