コード例 #1
0
        /// <summary>
        /// Gets the current controller type for the InputDevice name provided.
        /// </summary>
        /// <param name="inputDevice">The InputDevice from XR SDK.</param>
        protected virtual void RemoveController(InputDevice inputDevice)
        {
            using (RemoveControllerPerfMarker.Auto())
            {
                if (ActiveControllers.ContainsKey(inputDevice))
                {
                    GenericXRSDKController controller = ActiveControllers[inputDevice];

                    if (controller != null)
                    {
                        CoreServices.InputSystem?.RaiseSourceLost(controller.InputSource, controller);

                        RecyclePointers(controller.InputSource);

                        if (controller.Visualizer != null &&
                            controller.Visualizer.GameObjectProxy != null)
                        {
                            controller.Visualizer.GameObjectProxy.SetActive(false);
                        }
                    }

                    ActiveControllers.Remove(inputDevice);
                }
            }
        }
コード例 #2
0
        /// <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);
                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);

                CoreServices.InputSystem?.RaiseSourceDetected(detectedController.InputSource, detectedController);

                return(detectedController);
            }
        }
コード例 #3
0
        /// <inheritdoc/>
        public override void Update()
        {
            using (UpdatePerfMarker.Auto())
            {
                if (!IsEnabled)
                {
                    return;
                }

                base.Update();

                if (XRSubsystemHelpers.InputSubsystem == null || !XRSubsystemHelpers.InputSubsystem.running)
                {
                    return;
                }

                inputDevices.Clear();
                foreach (InputDeviceCharacteristics inputDeviceCharacteristics in DesiredInputCharacteristics)
                {
                    InputDevices.GetDevicesWithCharacteristics(inputDeviceCharacteristics, inputDevicesSubset);
                    foreach (InputDevice device in inputDevicesSubset)
                    {
                        if (!inputDevices.Contains(device))
                        {
                            inputDevices.Add(device);
                        }
                    }
                }

                foreach (InputDevice device in inputDevices)
                {
                    if (device.isValid)
                    {
                        GenericXRSDKController controller = GetOrAddController(device);

                        if (controller != null && lastInputDevices.Contains(device))
                        {
                            // Remove devices from our previously tracked list as we update them.
                            // This will allow us to remove all stale devices that were tracked
                            // last frame but not this one.
                            lastInputDevices.Remove(device);
                            controller.UpdateController(device);
                        }
                    }
                }

                foreach (InputDevice device in lastInputDevices)
                {
                    RemoveController(device);
                }

                lastInputDevices.Clear();
                lastInputDevices.AddRange(inputDevices);
            }
        }
コード例 #4
0
        /// <inheritdoc/>
        public override void Update()
        {
            Profiler.BeginSample("[MRTK] XRSDKDeviceManager.Update");

            base.Update();

            if (XRSDKSubsystemHelpers.InputSubsystem == null || !XRSDKSubsystemHelpers.InputSubsystem.running)
            {
                Profiler.EndSample(); // Update - early exit
                return;
            }

            InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.Controller, inputDevices);
            foreach (InputDevice device in inputDevices)
            {
                if (device.isValid)
                {
                    GenericXRSDKController controller = GetOrAddController(device);

                    if (controller == null)
                    {
                        continue;
                    }

                    if (!lastInputDevices.Contains(device))
                    {
                        CoreServices.InputSystem?.RaiseSourceDetected(controller.InputSource, controller);
                    }
                    else
                    {
                        // Remove devices from our previously tracked list as we update them.
                        // This will allow us to remove all stale devices that were tracked
                        // last frame but not this one.
                        lastInputDevices.Remove(device);
                        controller.UpdateController(device);
                    }
                }
            }

            foreach (InputDevice device in lastInputDevices)
            {
                GenericXRSDKController controller = GetOrAddController(device);
                if (controller != null)
                {
                    CoreServices.InputSystem?.RaiseSourceLost(controller.InputSource, controller);
                    RemoveController(device);
                }
            }

            lastInputDevices.Clear();
            lastInputDevices.AddRange(inputDevices);

            Profiler.EndSample(); // Update
        }
コード例 #5
0
        /// <summary>
        /// Removes the controller from the scene and handles any additional cleanup
        /// </summary>
        protected void RemoveControllerFromScene(GenericXRSDKController controller)
        {
            CoreServices.InputSystem?.RaiseSourceLost(controller.InputSource, controller);

            RecyclePointers(controller.InputSource);

            if (controller.Visualizer != null &&
                controller.Visualizer.GameObjectProxy != null)
            {
                controller.Visualizer.GameObjectProxy.SetActive(false);
            }
        }
コード例 #6
0
        /// <inheritdoc/>
        public override void Update()
        {
            using (UpdatePerfMarker.Auto())
            {
                base.Update();

                if (XRSDKSubsystemHelpers.InputSubsystem == null || !XRSDKSubsystemHelpers.InputSubsystem.running)
                {
                    return;
                }

                InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.HandTracking, inputDevices);
                foreach (InputDevice device in inputDevices)
                {
                    if (device.isValid)
                    {
                        GenericXRSDKController controller = GetOrAddController(device);

                        if (controller == null)
                        {
                            continue;
                        }

                        if (!lastInputDevices.Contains(device))
                        {
                            CoreServices.InputSystem?.RaiseSourceDetected(controller.InputSource, controller);
                        }
                        else
                        {
                            // Remove devices from our previously tracked list as we update them.
                            // This will allow us to remove all stale devices that were tracked
                            // last frame but not this one.
                            lastInputDevices.Remove(device);
                            controller.UpdateController(device);
                        }
                    }
                }

                foreach (InputDevice device in lastInputDevices)
                {
                    GenericXRSDKController controller = GetOrAddController(device);
                    if (controller != null)
                    {
                        CoreServices.InputSystem?.RaiseSourceLost(controller.InputSource, controller);
                        RemoveController(device);
                    }
                }

                lastInputDevices.Clear();
                lastInputDevices.AddRange(inputDevices);
            }
        }
コード例 #7
0
        /// <summary>
        /// Gets the current controller type for the InputDevice name provided.
        /// </summary>
        /// <param name="inputDevice">The InputDevice from XR SDK.</param>
        protected virtual void RemoveController(InputDevice inputDevice)
        {
            using (RemoveControllerPerfMarker.Auto())
            {
                GenericXRSDKController controller = GetOrAddController(inputDevice);

                if (controller != null)
                {
                    RemoveControllerFromScene(controller);
                    ActiveControllers.Remove(inputDevice);
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// Removes the controller from the scene and handles any additional cleanup
        /// </summary>
        protected void RemoveControllerFromScene(GenericXRSDKController controller)
        {
            Service?.RaiseSourceLost(controller.InputSource, controller);

            RecyclePointers(controller.InputSource);

            var visualizer = controller.Visualizer;

            if (!visualizer.IsNull() &&
                visualizer.GameObjectProxy != null)
            {
                visualizer.GameObjectProxy.SetActive(false);
            }
        }
コード例 #9
0
        /// <summary>
        /// Gets the current controller type for the InputDevice name provided.
        /// </summary>
        /// <param name="inputDevice">The InputDevice from XR SDK.</param>
        protected virtual void RemoveController(InputDevice inputDevice)
        {
            GenericXRSDKController controller = GetOrAddController(inputDevice);

            if (controller != null)
            {
                RecyclePointers(controller.InputSource);

                if (controller.Visualizer != null &&
                    controller.Visualizer.GameObjectProxy != null)
                {
                    controller.Visualizer.GameObjectProxy.SetActive(false);
                }

                ActiveControllers.Remove(inputDevice);
            }
        }
コード例 #10
0
        /// <summary>
        /// Gets the current controller type for the InputDevice name provided.
        /// </summary>
        /// <param name="inputDevice">The InputDevice from XR SDK.</param>
        protected virtual void RemoveController(InputDevice inputDevice)
        {
            Profiler.BeginSample("[MRTK] XRSDKDeviceManager.RemoveController");

            GenericXRSDKController controller = GetOrAddController(inputDevice);

            if (controller != null)
            {
                RecyclePointers(controller.InputSource);

                if (controller.Visualizer != null &&
                    controller.Visualizer.GameObjectProxy != null)
                {
                    controller.Visualizer.GameObjectProxy.SetActive(false);
                }

                ActiveControllers.Remove(inputDevice);
            }

            Profiler.EndSample(); // RemoveController
        }
コード例 #11
0
        /// <inheritdoc/>
        public override void Update()
        {
            base.Update();

            if (XRSDKSubsystemHelpers.InputSubsystem == null || !XRSDKSubsystemHelpers.InputSubsystem.running)
            {
                return;
            }

            if (!leftInputDevice.isValid)
            {
                if (wasLeftInputDeviceValid)
                {
                    GenericXRSDKController controller = GetOrAddController(leftInputDevice);

                    if (controller != null)
                    {
                        CoreServices.InputSystem?.RaiseSourceLost(controller.InputSource, controller);
                    }

                    RemoveController(leftInputDevice);
                    wasLeftInputDeviceValid = false;
                }

                leftInputDevice = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand);

                if (leftInputDevice.isValid)
                {
                    wasLeftInputDeviceValid = true;
                    GenericXRSDKController controller = GetOrAddController(leftInputDevice);

                    if (controller != null)
                    {
                        CoreServices.InputSystem?.RaiseSourceDetected(controller.InputSource, controller);
                    }
                }
            }
            else
            {
                GetOrAddController(leftInputDevice)?.UpdateController(leftInputDevice);
            }

            if (!rightInputDevice.isValid)
            {
                if (wasRightInputDeviceValid)
                {
                    GenericXRSDKController controller = GetOrAddController(rightInputDevice);

                    if (controller != null)
                    {
                        CoreServices.InputSystem?.RaiseSourceLost(controller.InputSource, controller);
                    }

                    RemoveController(rightInputDevice);
                    wasRightInputDeviceValid = false;
                }

                rightInputDevice = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);

                if (rightInputDevice.isValid)
                {
                    wasRightInputDeviceValid = true;
                    GenericXRSDKController controller = GetOrAddController(rightInputDevice);

                    if (controller != null)
                    {
                        CoreServices.InputSystem?.RaiseSourceDetected(controller.InputSource, controller);
                    }
                }
            }
            else
            {
                GetOrAddController(rightInputDevice)?.UpdateController(rightInputDevice);
            }
        }