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