public IEnumerator TestGazeProviderTargetUnityUi() { TestUtilities.PlayspaceToOriginLookingForward(); // spawn 3d object var cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.position = Vector3.forward; cube.transform.localScale = Vector3.one * 0.5f; yield return(null); // make sure we get the 3d object as a gaze target Assert.AreEqual(CoreServices.InputSystem.GazeProvider.GazeTarget, cube, "GazeProvider target is not set to 3d object (cube)"); // spawn 2d unity ui var canvas = UnityUiUtilities.CreateCanvas(0.002f); var toggle = UnityUiUtilities.CreateToggle(Color.gray, Color.blue, Color.green); toggle.transform.SetParent(canvas.transform, false); canvas.transform.position = Vector3.forward * 0.5f; yield return(null); // check if gaze target has changed to unity ui Assert.AreEqual(CoreServices.InputSystem.GazeProvider.GazeTarget, toggle.gameObject, "GazeProvider target is not set to toggle unity ui"); // destroy unity ui Object.DestroyImmediate(canvas.gameObject); yield return(null); // make sure gaze is back at 3d object Assert.AreEqual(CoreServices.InputSystem.GazeProvider.GazeTarget, cube, "GazeProvider target is not set to 3d object (cube)"); yield return(null); }
public IEnumerator NearInteractionTouchableUnityUiButton() { var canvas = UnityUiUtilities.CreateCanvas(0.002f); var button = UnityUiUtilities.CreateButton(Color.gray, Color.blue, Color.green); button.transform.SetParent(canvas.transform, false); var text = UnityUiUtilities.CreateText("test"); text.transform.SetParent(button.transform, false); Vector3 pressedPosition = objectPosition + Vector3.forward * 0.05f; canvas.transform.position = objectPosition; yield return(new WaitForFixedUpdate()); yield return(null); yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSim)); using (var catcher = new UnityButtonEventCatcher(button)) { // Touch started and completed when entering and exiting yield return(PlayModeTestUtilities.MoveHand(initialHandPosition, pressedPosition, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim)); Assert.AreEqual(0, catcher.Click); yield return(PlayModeTestUtilities.MoveHand(pressedPosition + Vector3.forward * 0.05f, initialHandPosition, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim)); Assert.AreEqual(1, catcher.Click); } Object.Destroy(canvas.gameObject); }
public IEnumerator NearInteractionTouchableUnityUiToggle() { var canvas = UnityUiUtilities.CreateCanvas(0.002f); var toggle = UnityUiUtilities.CreateToggle(Color.gray, Color.blue, Color.green); toggle.transform.SetParent(canvas.transform, false); var text = UnityUiUtilities.CreateText("test"); text.transform.SetParent(toggle.transform, false); Vector3 pressedPosition = objectPosition + Vector3.forward * 0.05f; canvas.transform.position = objectPosition; yield return(new WaitForFixedUpdate()); yield return(null); yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSim)); using (var catcher = new UnityToggleEventCatcher(toggle)) { // Turn on the toggle after exiting yield return(PlayModeTestUtilities.MoveHand(initialHandPosition, pressedPosition, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim)); Assert.IsFalse(catcher.IsOn); Assert.AreEqual(0, catcher.Changed); yield return(PlayModeTestUtilities.MoveHand(pressedPosition, initialHandPosition, ArticulatedHandPose.GestureId.Pinch, Handedness.Right, inputSim)); Assert.IsTrue(catcher.IsOn); Assert.AreEqual(1, catcher.Changed); // Turn off the toggle after exiting yield return(PlayModeTestUtilities.MoveHand(initialHandPosition, pressedPosition, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSim)); Assert.IsTrue(catcher.IsOn); Assert.AreEqual(1, catcher.Changed); yield return(PlayModeTestUtilities.MoveHand(pressedPosition, initialHandPosition, ArticulatedHandPose.GestureId.Pinch, Handedness.Right, inputSim)); Assert.IsFalse(catcher.IsOn); Assert.AreEqual(2, catcher.Changed); } Object.Destroy(canvas.gameObject); }
public IEnumerator NearInteractionTouchableDistance() { var touchableRect = CreateTouchable <NearInteractionTouchable>(0.15f); touchableRect.SetLocalForward(touchNormal); touchableRect.SetBounds(new Vector2(0.5f, 0.5f)); CreateTouchEventCatcher(touchableRect); var touchableVolume = CreateTouchable <NearInteractionTouchableVolume>(0.15f); CreateTouchEventCatcher(touchableVolume); var canvas = UnityUiUtilities.CreateCanvas(0.002f); var touchableUI = canvas.GetComponent <NearInteractionTouchableUnityUI>(); var button = UnityUiUtilities.CreateButton(Color.gray, Color.blue, Color.green); button.transform.SetParent(touchableUI.transform, false); // This constructor assigns an event handler, but the actual object isn't needed _ = new UnityButtonEventCatcher(button); yield return(new WaitForFixedUpdate()); yield return(null); touchableRect.gameObject.name = "Rect Touchable"; touchableVolume.gameObject.name = "Volume Touchable"; touchableUI.gameObject.name = "UnityUI Touchable"; float distSurface = 0.3f; touchableRect.transform.position = new Vector3(-1, 0, distSurface); touchableVolume.transform.position = new Vector3(0, 0, distSurface); touchableUI.transform.position = new Vector3(1, 0, distSurface); yield return(TestTouchableDistances(touchableRect, 0.0075f, touchableRect.gameObject)); yield return(TestTouchableDistances(touchableVolume, 0.0075f, touchableVolume.gameObject)); yield return(TestTouchableDistances(touchableUI, 0.0f, button.gameObject)); Object.Destroy(touchableRect.gameObject); Object.Destroy(touchableVolume.gameObject); Object.Destroy(touchableUI.gameObject); }