/// <summary>
        /// Constructor.
        /// </summary>
        public MicrosoftArticulatedHand(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
            : base(trackingState, controllerHandedness, inputSource, interactions, new ArticulatedHandDefinition(inputSource, controllerHandedness))
        {
            handDefinition   = Definition as ArticulatedHandDefinition;
            handMeshProvider = controllerHandedness == Handedness.Left ? OpenXRHandMeshProvider.Left : OpenXRHandMeshProvider.Right;
            handMeshProvider?.SetInputSource(inputSource);

#if MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA)
#if MSFT_OPENXR_0_2_0_OR_NEWER
            handTracker = controllerHandedness == Handedness.Left ? HandTracker.Left : HandTracker.Right;
#else
            handTracker = new HandTracker(controllerHandedness == Handedness.Left ? Preview.Handedness.Left : Preview.Handedness.Right, Preview.HandPoseType.Tracked);
#endif
#endif // MSFT_OPENXR && (UNITY_STANDALONE_WIN || UNITY_WSA)
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 protected BaseWindowsMixedRealitySource(TrackingState trackingState, Handedness sourceHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
     : base(trackingState, sourceHandedness, inputSource, interactions)
 {
 }
        public static void UpdateInteractionMappingBool(this MixedRealityInteractionMapping interactionMapping, IMixedRealityInputSource inputSource, Handedness controllerHandedness)
        {
            // If our value changed raise it.
            if (interactionMapping.Changed)
            {
                // Raise input system Event if it enabled
                if (interactionMapping.BoolData)
                {
                    MixedRealityToolkit.InputSystem?.RaiseOnInputDown(inputSource, controllerHandedness, interactionMapping.MixedRealityInputAction);
                }
                else
                {
                    MixedRealityToolkit.InputSystem?.RaiseOnInputUp(inputSource, controllerHandedness, interactionMapping.MixedRealityInputAction);
                }
            }

            if (interactionMapping.Updated)
            {
                MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(inputSource, controllerHandedness, interactionMapping.MixedRealityInputAction);
            }
        }
示例#4
0
 public InternalGazePointer(GazeProvider gazeProvider, string pointerName, IMixedRealityInputSource inputSourceParent, LayerMask[] raycastLayerMasks, float pointerExtent, Transform gazeTransform, BaseRayStabilizer stabilizer)
     : base(pointerName, inputSourceParent)
 {
     this.gazeProvider             = gazeProvider;
     PrioritizedLayerMasksOverride = raycastLayerMasks;
     this.pointerExtent            = pointerExtent;
     this.gazeTransform            = gazeTransform;
     this.stabilizer      = stabilizer;
     IsInteractionEnabled = true;
 }
示例#5
0
 /// <summary>
 /// Press this pointer. This sends a pointer down event across the input system.
 /// </summary>
 /// <param name="mixedRealityInputAction">The input action that corresponds to the pressed button or axis.</param>
 /// <param name="handedness">Optional handedness of the source that pressed the pointer.</param>
 /// <param name="inputSource"></param>
 public void RaisePointerDown(MixedRealityInputAction mixedRealityInputAction, Handedness handedness = Handedness.None, IMixedRealityInputSource inputSource = null)
 {
     isDown             = true;
     currentHandedness  = handedness;
     currentInputSource = inputSource;
     gazeProvider.InputSystem?.RaisePointerDown(this, mixedRealityInputAction, handedness, inputSource);
 }
示例#6
0
        /// <inheritdoc />
        public override void Enable()
        {
            if (!UInput.mousePresent)
            {
                Disable();
                return;
            }

            if (Controller != null)
            {
                // device manager has already been set up
                return;
            }

#if UNITY_EDITOR
            if (UnityEditor.EditorWindow.focusedWindow != null)
            {
                UnityEditor.EditorWindow.focusedWindow.ShowNotification(new GUIContent("Press \"ESC\" to regain mouse control"));
            }
#endif

            Cursor.visible   = false;
            Cursor.lockState = CursorLockMode.Locked;

            IMixedRealityInputSource mouseInputSource = null;

            MixedRealityRaycaster.DebugEnabled = true;

            const Handedness handedness     = Handedness.Any;
            System.Type      controllerType = typeof(MouseController);

            // Make sure that the handedness declared in the controller attribute matches what we expect
            {
                var controllerAttribute = MixedRealityControllerAttribute.Find(controllerType);
                if (controllerAttribute != null)
                {
                    Handedness[] handednesses = controllerAttribute.SupportedHandedness;
                    Debug.Assert(handednesses.Length == 1 && handednesses[0] == Handedness.Any, "Unexpected mouse handedness declared in MixedRealityControllerAttribute");
                }
            }

            IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;

            if (inputSystem != null)
            {
                var pointers = RequestPointers(SupportedControllerType.Mouse, handedness);
                mouseInputSource = inputSystem.RequestNewGenericInputSource("Mouse Input", pointers);
            }

            Controller = new MouseController(TrackingState.NotApplicable, handedness, mouseInputSource);

            if (mouseInputSource != null)
            {
                for (int i = 0; i < mouseInputSource.Pointers.Length; i++)
                {
                    mouseInputSource.Pointers[i].Controller = Controller;
                }
            }

            Controller.SetupConfiguration(typeof(MouseController));
            inputSystem?.RaiseSourceDetected(Controller.InputSource, Controller);
        }
        public IEnumerator TestInputActions()
        {
            AssembleInteractableButton(
                out Interactable interactable,
                out Transform 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.");

            GameObject.Destroy(interactable.gameObject);
        }
 /// <summary>
 /// Used to initialize/reset the event and populate the data.
 /// </summary>
 /// <param name="inputSource"></param>
 /// <param name="inputAction"></param>
 public void Initialize(IMixedRealityInputSource inputSource, MixedRealityInputAction inputAction)
 {
     BaseInitialize(inputSource, inputAction);
 }
 /// <summary>
 /// Used to initialize/reset the event and populate the data.
 /// </summary>
 /// <param name="inputSource"></param>
 /// <param name="handedness"></param>
 /// <param name="inputAction"></param>
 public void Initialize(IMixedRealityInputSource inputSource, Handedness handedness, MixedRealityInputAction inputAction)
 {
     BaseInitialize(inputSource, inputAction);
     Handedness = handedness;
 }
 public WindowsMixedRealityArticulatedHandDefinition(IMixedRealityInputSource source, Handedness handedness) : base(source, handedness)
 {
 }
示例#11
0
 /// <summary>
 /// Constructor.
 /// </summary>
 protected GenericPointer(string pointerName, IMixedRealityInputSource inputSourceParent)
 {
     PointerId              = (CoreServices.InputSystem?.FocusProvider != null) ? CoreServices.InputSystem.FocusProvider.GenerateNewPointerId() : 0;
     PointerName            = pointerName;
     this.inputSourceParent = inputSourceParent;
 }
示例#12
0
 /// <summary>
 /// Populates the event with data.
 /// </summary>
 /// <param name="inputSource"></param>
 /// <param name="controller"></param>
 public void Initialize(IMixedRealityInputSource inputSource, IMixedRealityController controller)
 {
     // NOTE: Source State events do not have an associated Input Action.
     BaseInitialize(inputSource, MixedRealityInputAction.None);
     Controller = controller;
 }
示例#13
0
        public GenericJoystickController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
            : base(trackingState, controllerHandedness, inputSource, interactions)
        {
            // Update the spatial pointer rotation with the preconfigured offset angle
            if (PointerOffsetAngle != 0f && Interactions != null)
            {
                MixedRealityInteractionMapping pointerMapping = null;
                for (int i = 0; i < Interactions.Length; i++)
                {
                    MixedRealityInteractionMapping mapping = Interactions[i];
                    if (mapping.InputType == DeviceInputType.SpatialPointer)
                    {
                        pointerMapping = mapping;
                        break;
                    }
                }

                if (pointerMapping == null)
                {
                    Debug.LogWarning($"A pointer offset is defined for {GetType()}, but no spatial pointer mapping could be found.");
                    return;
                }

                MixedRealityPose startingRotation = MixedRealityPose.ZeroIdentity;
                startingRotation.Rotation *= Quaternion.AngleAxis(PointerOffsetAngle, Vector3.left);
                pointerMapping.PoseData    = startingRotation;
            }
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="source">The input source backing this definition instance. Used for raising events.</param>
 /// <param name="handedness">The handedness that this definition instance represents.</param>
 public ArticulatedHandDefinition(IMixedRealityInputSource source, Handedness handedness) : base(handedness)
 {
     InputSource = source;
 }
        /// <summary>
        /// Fires speech command to default input system with given string and input action type.
        /// If no input source is provided, then the first detected input source is used in conjunction with the raised event.
        /// </summary>
        public static IEnumerator ExecuteSpeechCommand(string voiceCommand, MixedRealityInputAction inputAction, IMixedRealityInputSource inputSource = null)
        {
            if (inputSource == null)
            {
                // 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.");
                inputSource = defaultInputSource;
            }

            // Raise a voice select input event, then wait for transition to take place
            // Wait for at least one frame explicitly to ensure the input goes through
            SpeechCommands commands = new SpeechCommands(voiceCommand, KeyCode.None, inputAction);

            CoreServices.InputSystem.RaiseSpeechCommandRecognized(inputSource, RecognitionConfidenceLevel.High, new System.TimeSpan(100), System.DateTime.Now, commands);
            yield return(PlayModeTestUtilities.WaitForInputSystemUpdate());
        }
示例#16
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public MicrosoftMotionController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
     : base(trackingState, controllerHandedness, inputSource, interactions, new WindowsMixedRealityControllerDefinition(controllerHandedness))
 {
 }
示例#17
0
 /// <summary>
 /// Constructor.
 /// </summary>
 protected SimulatedHand(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
     : base(trackingState, controllerHandedness, inputSource, interactions)
 {
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 public WindowsMixedRealityXRSDKArticulatedHand(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
     : base(trackingState, controllerHandedness, inputSource, interactions)
 {
     handDefinition = new WindowsMixedRealityArticulatedHandDefinition(inputSource, controllerHandedness);
 }
示例#19
0
 /// <summary>
 /// Default constructor used by reflection for profiles
 /// </summary>
 /// <param name="trackingState"></param>
 /// <param name="controllerHandedness"></param>
 /// <param name="inputSource"></param>
 /// <param name="interactions"></param>
 public OculusQuestHand(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
     : base(trackingState, controllerHandedness, inputSource, interactions)
 {
     palmFilter.Reset();
     indexTipFilter.Reset();
     pinchStrengthProp = Shader.PropertyToID(MRTKOculusConfig.Instance.PinchStrengthMaterialProperty);
 }
 /// <summary>
 /// Populates the event with data.
 /// </summary>
 /// <param name="inputSource"></param>
 /// <param name="controller"></param>
 /// <param name="data"></param>
 public void Initialize(IMixedRealityInputSource inputSource, IMixedRealityController controller, T data)
 {
     Initialize(inputSource, controller);
     SourceData = data;
 }
示例#21
0
        /// <summary>
        /// Used to initialize/reset the event and populate the data.
        /// </summary>
        /// <param name="pointer"></param>
        /// <param name="inputAction"></param>
        /// <param name="handedness"></param>
        /// <param name="inputSource"></param>
        /// <param name="count"></param>
        public void Initialize(IMixedRealityPointer pointer, MixedRealityInputAction inputAction, Handedness handedness = Handedness.None, IMixedRealityInputSource inputSource = null, int count = 0)
        {
            if (inputSource != null)
            {
                Initialize(inputSource, handedness, inputAction);
            }
            else
            {
                Initialize(pointer.InputSourceParent, handedness, inputAction);
            }

            Pointer = pointer;
            Count   = count;
        }
示例#22
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="trackingState"></param>
        /// <param name="controllerHandedness"></param>
        /// <param name="inputSource"></param>
        /// <param name="interactions"></param>
        protected BaseController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
        {
            TrackingState        = trackingState;
            ControllerHandedness = controllerHandedness;
            InputSource          = inputSource;
            Interactions         = interactions;

            IsPositionAvailable   = false;
            IsPositionApproximate = false;
            IsRotationAvailable   = false;

            Enabled = true;
        }
示例#23
0
 /// <summary>
 /// Only for use when initializing Gaze Pointer on startup.
 /// </summary>
 /// <param name="gazeInputSource"></param>
 internal void SetGazeInputSourceParent(IMixedRealityInputSource gazeInputSource)
 {
     InputSourceParent = gazeInputSource;
 }
        /// <summary>
        /// Gets or adds a controller using the InputDevice name provided.
        /// </summary>
        /// <param name="inputDevice">The InputDevice from XR SDK.</param>
        /// <returns>The controller reference.</returns>
        protected virtual GenericXRSDKController GetOrAddController(InputDevice inputDevice)
        {
            using (GetOrAddControllerPerfMarker.Auto())
            {
                // If a device is already registered with the ID provided, just return it.
                if (ActiveControllers.ContainsKey(inputDevice))
                {
                    var controller = ActiveControllers[inputDevice];
                    Debug.Assert(controller != null);
                    return(controller);
                }

                Handedness controllingHand;

                if (inputDevice.characteristics.HasFlag(InputDeviceCharacteristics.Left))
                {
                    controllingHand = Handedness.Left;
                }
                else if (inputDevice.characteristics.HasFlag(InputDeviceCharacteristics.Right))
                {
                    controllingHand = Handedness.Right;
                }
                else
                {
                    controllingHand = Handedness.None;
                }

                SupportedControllerType currentControllerType = GetCurrentControllerType(inputDevice);
                Type controllerType = GetControllerType(currentControllerType);

                if (controllerType == null)
                {
                    return(null);
                }

                InputSourceType inputSourceType = GetInputSourceType(currentControllerType);

                IMixedRealityPointer[]   pointers           = RequestPointers(currentControllerType, controllingHand);
                IMixedRealityInputSource inputSource        = Service?.RequestNewGenericInputSource($"{currentControllerType} Controller {controllingHand}", pointers, inputSourceType);
                GenericXRSDKController   detectedController = Activator.CreateInstance(controllerType, TrackingState.NotTracked, controllingHand, inputSource, null) as GenericXRSDKController;

                if (detectedController == null || !detectedController.Enabled)
                {
                    // Controller failed to be set up correctly.
                    Debug.LogError($"Failed to create {controllerType.Name} controller");

                    // Return null so we don't raise the source detected.
                    return(null);
                }

                for (int i = 0; i < detectedController.InputSource?.Pointers?.Length; i++)
                {
                    detectedController.InputSource.Pointers[i].Controller = detectedController;
                }

                ActiveControllers.Add(inputDevice, detectedController);

                Service?.RaiseSourceDetected(detectedController.InputSource, detectedController);

                return(detectedController);
            }
        }
示例#25
0
 /// <summary>
 /// Release this pointer. This sends pointer clicked and pointer up events across the input system.
 /// </summary>
 /// <param name="mixedRealityInputAction">The input action that corresponds to the released button or axis.</param>
 /// <param name="handedness">Optional handedness of the source that released the pointer.</param>
 /// <param name="inputSource"></param>
 public void RaisePointerUp(MixedRealityInputAction mixedRealityInputAction, Handedness handedness = Handedness.None, IMixedRealityInputSource inputSource = null)
 {
     isDown             = false;
     currentHandedness  = Handedness.None;
     currentInputSource = null;
     gazeProvider.InputSystem?.RaisePointerClicked(this, mixedRealityInputAction, 0, handedness, inputSource);
     gazeProvider.InputSystem?.RaisePointerUp(this, mixedRealityInputAction, handedness, inputSource);
 }
示例#26
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="pointerName"></param>
 /// <param name="inputSourceParent"></param>
 public GenericPointer(string pointerName, IMixedRealityInputSource inputSourceParent)
 {
     PointerId              = (InputSystem?.FocusProvider != null) ? InputSystem.FocusProvider.GenerateNewPointerId() : 0;
     PointerName            = pointerName;
     this.inputSourceParent = inputSourceParent;
 }
示例#27
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public WindowsMixedRealityXRSDKMotionController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
     : base(trackingState, controllerHandedness, inputSource, interactions)
 {
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 public OculusTouchController(TrackingState trackingState, Handedness controllerHandedness,
                              IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
     : base(trackingState, controllerHandedness, inputSource, interactions)
 {
 }
 public static void UpdateInteractionMappingFloat(this MixedRealityInteractionMapping interactionMapping, IMixedRealityInputSource inputSource, Handedness controllerHandedness)
 {
     // If our value changed raise it.
     if (interactionMapping.Updated)
     {
         // Raise input system Event if it enabled
         MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(inputSource, controllerHandedness, interactionMapping.MixedRealityInputAction, interactionMapping.FloatData);
     }
 }
 public GenericOpenVRController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
     : base(trackingState, controllerHandedness, inputSource, interactions)
 {
     nodeType = controllerHandedness == Handedness.Left ? XRNode.LeftHand : XRNode.RightHand;
 }