コード例 #1
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);
            }
        }
コード例 #2
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
        }
コード例 #3
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);
            }
        }