Beispiel #1
0
 /// <summary>
 /// Changes the state of the simulated motion controller.
 /// </summary>
 /// <param name="isSelecting">Whether the motion controller should be selecting something.</param>
 /// <param name="isGrabbing">Whether the motion controller should be grabbing something.</param>
 /// <param name="isPressingMenu">Whether the menu button of the motion controller should be pressed down.</param>
 /// <param name="waitForFixedUpdate">If true, waits for a fixed update after moving to the new state.</param>
 public IEnumerator SetState(SimulatedMotionControllerButtonState buttonStateNew, bool waitForFixedUpdate = true)
 {
     buttonState = buttonStateNew;
     for (var iter = PlayModeTestUtilities.MoveMotionController(position, position, buttonState, handedness, simulationService, 1); iter.MoveNext();)
     {
         yield return(iter.Current);
     }
     if (waitForFixedUpdate)
     {
         yield return(new WaitForFixedUpdate());
     }
 }
Beispiel #2
0
        public static IEnumerator HideController(Handedness handedness, InputSimulationService inputSimulationService)
        {
            yield return(null);

            SimulatedMotionControllerData        motionControllerData = handedness == Handedness.Right ? inputSimulationService.MotionControllerDataRight : inputSimulationService.MotionControllerDataLeft;
            SimulatedMotionControllerButtonState defaultButtonState   = new SimulatedMotionControllerButtonState();

            motionControllerData.Update(false, defaultButtonState, UpdateMotionControllerPose(handedness, Vector3.zero, Quaternion.identity));

            // Wait one frame for the motion controller to actually disappear
            yield return(null);
        }
Beispiel #3
0
        /// <summary>
        /// Combined sequence of selecting and unselecting
        /// </summary>
        public override IEnumerator Click()
        {
            SimulatedMotionControllerButtonState selectButtonState = new SimulatedMotionControllerButtonState
            {
                IsSelecting = true
            };

            yield return(SetState(selectButtonState));

            yield return(null);

            SimulatedMotionControllerButtonState defaultButtonState = new SimulatedMotionControllerButtonState();

            yield return(SetState(defaultButtonState));

            yield return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Moves the motion controller from startPos to endPos.
        /// </summary>
        /// <remarks>
        /// <para>Note that numSteps defaults to a value of -1, which is a sentinel value to indicate that the
        /// default number of steps should be used (i.e. ControllerMoveSteps). ControllerMoveSteps is not a compile
        /// time constant, which is a requirement for default parameter values.</para>
        /// </remarks>
        public static IEnumerator MoveMotionController(
            Vector3 startPos, Vector3 endPos, SimulatedMotionControllerButtonState buttonState,
            Handedness handedness, InputSimulationService inputSimulationService,
            int numSteps = ControllerMoveStepsSentinelValue)
        {
            Debug.Assert(handedness == Handedness.Right || handedness == Handedness.Left, "handedness must be either right or left");
            numSteps = CalculateNumSteps(numSteps);

            for (int i = 1; i <= numSteps; i++)
            {
                float   t = i / (float)numSteps;
                Vector3 motionControllerPos         = Vector3.Lerp(startPos, endPos, t);
                var     motionControllerDataUpdater = UpdateMotionControllerPose(
                    handedness,
                    motionControllerPos,
                    Quaternion.identity);
                SimulatedMotionControllerData motionControllerData = handedness == Handedness.Right ? inputSimulationService.MotionControllerDataRight : inputSimulationService.MotionControllerDataLeft;
                motionControllerData.Update(true, buttonState, motionControllerDataUpdater);
                yield return(null);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Combined sequence of selecting, moving, and releasing.
        /// </summary>
        /// <param name="positionToRelease">The position to which the hand moves while pinching</param>
        /// <param name="waitForFinalFixedUpdate">Wait for a final physics update after releasing</param>
        /// <param name="numSteps">Number of steps of the hand movement</param>
        public IEnumerator SelectAndThrowAt(Vector3 positionToRelease, bool waitForFinalFixedUpdate, int numSteps = 30)
        {
            SimulatedMotionControllerButtonState selectButtonState = new SimulatedMotionControllerButtonState
            {
                IsSelecting = true
            };

            for (var iter = SetState(selectButtonState); iter.MoveNext();)
            {
                yield return(iter.Current);
            }
            for (var iter = MoveTo(positionToRelease, numSteps); iter.MoveNext();)
            {
                yield return(iter.Current);
            }
            SimulatedMotionControllerButtonState defaultButtonState = new SimulatedMotionControllerButtonState();

            for (var iter = SetState(defaultButtonState, waitForFinalFixedUpdate); iter.MoveNext();)
            {
                yield return(iter.Current);
            }
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        public static IEnumerator ShowMontionController(Handedness handedness, InputSimulationService inputSimulationService, SimulatedMotionControllerButtonState buttonState, Vector3 motionControllerLocation)
        {
            yield return(null);

            Debug.Assert((ControllerSimulationMode.MotionController == inputSimulationService.ControllerSimulationMode), "The current ControllerSimulationMode must be MotionController!");
            SimulatedMotionControllerData motionControllerData = handedness == Handedness.Right ? inputSimulationService.MotionControllerDataRight : inputSimulationService.MotionControllerDataLeft;

            motionControllerData.Update(true, buttonState, UpdateMotionControllerPose(handedness, motionControllerLocation, Quaternion.identity));

            // Wait one frame for the hand to actually appear
            yield return(null);
        }
Beispiel #8
0
        /// <summary>
        /// Shows the motion controller in the default state, at the origin
        /// </summary>
        public static IEnumerator ShowMontionController(Handedness handedness, InputSimulationService inputSimulationService)
        {
            SimulatedMotionControllerButtonState defaultButtonState = new SimulatedMotionControllerButtonState();

            yield return(ShowMontionController(handedness, inputSimulationService, defaultButtonState, Vector3.zero));
        }
Beispiel #9
0
        public static IEnumerator SetMotionControllerRotation(Quaternion fromRotation, Quaternion toRotation, Vector3 motionControllerPos, SimulatedMotionControllerButtonState buttonState,
                                                              Handedness handedness, int numSteps, InputSimulationService inputSimulationService)
        {
            Debug.Assert(handedness == Handedness.Right || handedness == Handedness.Left, "handedness must be either right or left");

            for (int i = 1; i <= numSteps; i++)
            {
                float      t = i / (float)numSteps;
                Quaternion motionControllerRotation    = Quaternion.Lerp(fromRotation, toRotation, t);
                var        motionControllerDataUpdater = UpdateMotionControllerPose(
                    handedness,
                    motionControllerPos,
                    motionControllerRotation);
                SimulatedMotionControllerData motionControllerData = handedness == Handedness.Right ? inputSimulationService.MotionControllerDataRight : inputSimulationService.MotionControllerDataLeft;
                motionControllerData.Update(true, buttonState, motionControllerDataUpdater);
                yield return(null);
            }
        }
Beispiel #10
0
 public static IEnumerator SetMotionControllerState(Vector3 motionControllerPos, SimulatedMotionControllerButtonState buttonState, Handedness handedness, InputSimulationService inputSimulationService)
 {
     yield return(MoveMotionController(motionControllerPos, motionControllerPos, buttonState, handedness, inputSimulationService, 2));
 }
Beispiel #11
0
        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);
        }