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; ManipulationHandler manipulationHandler = cube.AddComponent<ManipulationHandler>(); CursorContextManipulationHandler cursorContextManipulationHandler = cube.AddComponent<CursorContextManipulationHandler>(); yield return new WaitForFixedUpdate(); yield return null; // Move cube back to original position (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(cursorContextManipulationHandler); Object.Destroy(manipulationHandler); }
/// <inheritdoc /> public void Migrate(GameObject gameObject) { var manipHandler = gameObject.GetComponent <ManipulationHandler>(); var objManip = gameObject.AddComponent <ObjectManipulator>(); objManip.enabled = manipHandler.enabled; objManip.HostTransform = manipHandler.HostTransform; switch (manipHandler.ManipulationType) { case ManipulationHandler.HandMovementType.OneHandedOnly: objManip.ManipulationType = ManipulationHandFlags.OneHanded; break; case ManipulationHandler.HandMovementType.TwoHandedOnly: objManip.ManipulationType = ManipulationHandFlags.TwoHanded; break; case ManipulationHandler.HandMovementType.OneAndTwoHanded: objManip.ManipulationType = ManipulationHandFlags.OneHanded | ManipulationHandFlags.TwoHanded; break; } objManip.AllowFarManipulation = manipHandler.AllowFarManipulation; if (manipHandler.OneHandRotationModeNear == manipHandler.OneHandRotationModeFar) { MigrateOneHandRotationModes(ref objManip, manipHandler.OneHandRotationModeNear, ManipulationProximityFlags.Near | ManipulationProximityFlags.Far); } else { MigrateOneHandRotationModes(ref objManip, manipHandler.OneHandRotationModeNear, ManipulationProximityFlags.Near); MigrateOneHandRotationModes(ref objManip, manipHandler.OneHandRotationModeFar, ManipulationProximityFlags.Far); } switch (manipHandler.TwoHandedManipulationType) { case ManipulationHandler.TwoHandedManipulation.Scale: objManip.TwoHandedManipulationType = TransformFlags.Scale; break; case ManipulationHandler.TwoHandedManipulation.Rotate: objManip.TwoHandedManipulationType = TransformFlags.Rotate; break; case ManipulationHandler.TwoHandedManipulation.MoveScale: objManip.TwoHandedManipulationType = TransformFlags.Move | TransformFlags.Scale; break; case ManipulationHandler.TwoHandedManipulation.MoveRotate: objManip.TwoHandedManipulationType = TransformFlags.Move | TransformFlags.Rotate; break; case ManipulationHandler.TwoHandedManipulation.RotateScale: objManip.TwoHandedManipulationType = TransformFlags.Rotate | TransformFlags.Scale; break; case ManipulationHandler.TwoHandedManipulation.MoveRotateScale: objManip.TwoHandedManipulationType = TransformFlags.Move | TransformFlags.Rotate | TransformFlags.Scale; break; } objManip.ReleaseBehavior = (ObjectManipulator.ReleaseBehaviorType)manipHandler.ReleaseBehavior; if (manipHandler.ConstraintOnRotation != RotationConstraintType.None) { var rotateConstraint = objManip.EnsureComponent <RotationAxisConstraint>(); rotateConstraint.TargetTransform = manipHandler.HostTransform; rotateConstraint.ConstraintOnRotation = RotationConstraintHelper.ConvertToAxisFlags(manipHandler.ConstraintOnRotation); } if (manipHandler.ConstraintOnMovement == MovementConstraintType.FixDistanceFromHead) { var moveConstraint = objManip.EnsureComponent <FixedDistanceConstraint>(); moveConstraint.TargetTransform = manipHandler.HostTransform; moveConstraint.ConstraintTransform = CameraCache.Main.transform; } objManip.SmoothingActive = manipHandler.SmoothingActive; objManip.MoveLerpTime = manipHandler.SmoothingAmoutOneHandManip; objManip.RotateLerpTime = manipHandler.SmoothingAmoutOneHandManip; objManip.ScaleLerpTime = manipHandler.SmoothingAmoutOneHandManip; objManip.OnManipulationStarted = manipHandler.OnManipulationStarted; objManip.OnManipulationEnded = manipHandler.OnManipulationEnded; objManip.OnHoverEntered = manipHandler.OnHoverEntered; objManip.OnHoverExited = manipHandler.OnHoverExited; // finally check if there's a CursorContextManipulationHandler on the gameObject that we have to swap CursorContextManipulationHandler cursorContextManipHandler = gameObject.GetComponent <CursorContextManipulationHandler>(); if (cursorContextManipHandler) { gameObject.AddComponent <CursorContextObjectManipulator>(); // remove old component Object.DestroyImmediate(cursorContextManipHandler); } Object.DestroyImmediate(manipHandler); }