private void OnXRStopped()
 {
     StopSteamVR();
     LegacyActive   = false;
     XRPluginActive = false;
     CurrentSDK     = InputSDK.None;
     UpdateDevices();
 }
        public void GetSDK()
        {
            if (!IsVRInitialized)
            {
                CurrentSDK = InputSDK.None;
                return;
            }

            if (CurrentSDK != InputSDK.None)
            {
                return;
            }

            var isXRPlugin   = VRPlugin == VRMode.XRPlugin;
            var steamvrFound = IsSteamVR();
            var isLegacy     = !isXRPlugin;

            if (steamvrFound && isLegacy)
            {
                CurrentSDK = InputSDK.SteamVR;
                return;
            }

#if ENABLE_INPUT_SYSTEM
            if (UseNewInputSystem)
            {
                CurrentSDK = InputSDK.InputSystem;
                return;
            }
#endif

            if (isXRPlugin)
            {
                XRPluginLoader = XRPluginLoader.ToLower();
                if (XRPluginLoader == OculusLoader.ToLower())
                {
                    CurrentSDK = UseOVRInputs ? InputSDK.Oculus : InputSDK.XRInput;
                    return;
                }

#if ENABLE_INPUT_SYSTEM
                if (XRPluginLoader == OpenXRLoader.ToLower())
                {
                    CurrentSDK = InputSDK.InputSystem;
                    return;
                }
#endif

                if (XRPluginLoader == OpenVRLoader.ToLower())
                {
                    if (!steamvrFound)
                    {
                        Debug.LogWarning($"HVR: {OpenVRLoader} active without SteamVR installed or HVR_STEAMVR define set.");
                    }
                    CurrentSDK = InputSDK.SteamVR;
                    return;
                }


                CurrentSDK = InputSDK.XRInput;
                return;
            }

            //legacy vr
            if (LeftXRInputSystem == XRInputSystem.Oculus || RightXRInputSystem == XRInputSystem.Oculus)
            {
                CurrentSDK = UseOVRInputs ? InputSDK.Oculus : InputSDK.XRInput;
                return;
            }

            CurrentSDK = InputSDK.XRInput;
        }
        private HVRController UpdateController(XRInputSystem sdk, InputDevice device, HVRHandSide side)
        {
            HVRInputSettings  inputMap = null;
            Vector2           deadZone = Vector2.zero;
            HVRControllerType controllerType;

            //var hasTrackPad = side == HVRHandSide.Left ? LeftHasTrackPad : RightHasTrackPad;
            var wasNone = CurrentSDK == InputSDK.None;

            GetSDK();

            if (CurrentSDK == InputSDK.Oculus)
            {
#if !HVR_OCULUS
                Debug.LogWarning($"OVRInputs cannot be used because HVR_OCULUS define symbol is missing. Oculus Asset and the Hurricane Oculus Integration is required to use OVRInputs." +
                                 $"Falling back to XRInputs.");
                CurrentSDK = InputSDK.XRInput;
#endif
            }

            if (wasNone && CurrentSDK != InputSDK.None)
            {
                Debug.Log($"InputSDK : {CurrentSDK}");
            }

            switch (sdk)
            {
            case XRInputSystem.WMROpenVR:
                inputMap       = WMROpenVRInputMap;
                deadZone       = WMRDeadzone;
                controllerType = HVRControllerType.WMR;
                break;

            case XRInputSystem.ReverbG2:
                deadZone       = WMRDeadzone;
                inputMap       = WMRWithButtonsInputMap;
                controllerType = HVRControllerType.WMRButtons;
                break;

            case XRInputSystem.WMR:
                inputMap       = WMRInputMap;
                deadZone       = WMRDeadzone;
                controllerType = HVRControllerType.WMR;
                break;

            case XRInputSystem.OculusOpenVR:
                inputMap       = OculusOpenVRInputMap;
                deadZone       = OculusDeadzone;
                controllerType = HVRControllerType.Oculus;
                break;

            case XRInputSystem.Oculus:
                inputMap       = OculusInputMap;
                deadZone       = OculusDeadzone;
                controllerType = HVRControllerType.Oculus;
                break;

            case XRInputSystem.Vive:
                deadZone       = ViveDeadzone;
                inputMap       = ViveInputMap;
                controllerType = HVRControllerType.Vive;
                break;

            case XRInputSystem.Knuckles:
                deadZone       = KnucklesDeadzone;
                inputMap       = KnucklesInputMap;
                controllerType = HVRControllerType.Knuckles;
                break;

            case XRInputSystem.Cosmos:
                inputMap       = CosmosInputMap;
                deadZone       = CosmosDeadzone;
                controllerType = HVRControllerType.Cosmos;
                break;

            case XRInputSystem.None:
                inputMap       = OculusInputMap;
                controllerType = HVRControllerType.None;
                break;

            default:
                inputMap       = OculusInputMap;
                deadZone       = OculusDeadzone;
                controllerType = HVRControllerType.Oculus;
                break;
            }


            if (!inputMap)
            {
                inputMap = OculusInputMap;
            }


            HVRController controller = null;

            if (side == HVRHandSide.Left)
            {
                if (LeftOculusController)
                {
                    LeftOculusController.enabled = false;
                }
                if (LeftSteamController)
                {
                    LeftSteamController.enabled = false;
                }
                if (LeftXRInputController)
                {
                    LeftXRInputController.enabled = false;
                }
                if (LeftInputSystemController)
                {
                    LeftInputSystemController.enabled = false;
                }
            }
            else
            {
                if (RightOculusController)
                {
                    RightOculusController.enabled = false;
                }
                if (RightSteamController)
                {
                    RightSteamController.enabled = false;
                }
                if (RightXRInputController)
                {
                    RightXRInputController.enabled = false;
                }
                if (RightInputSystemController)
                {
                    RightInputSystemController.enabled = false;
                }
            }

            switch (CurrentSDK)
            {
            case InputSDK.None:
            case InputSDK.XRInput:

                controller = side == HVRHandSide.Left ? LeftXRInputController : RightXRInputController;

                HVRXRInputController xrController = controller as HVRXRInputController;

                if (!controller)
                {
                    xrController = gameObject.AddComponent <HVRXRInputController>();
                    controller   = xrController;

                    if (side == HVRHandSide.Left)
                    {
                        LeftXRInputController = controller;
                    }
                    else
                    {
                        RightXRInputController = controller;
                    }
                }

                break;

            case InputSDK.Oculus:

#if HVR_OCULUS
                controller = side == HVRHandSide.Left ? LeftOculusController : RightOculusController;

                if (!controller)
                {
                    var oculusController = gameObject.AddComponent <HVROculusController>();
                    controller = oculusController;
                    oculusController.OVRHaptics = OVRHaptics;

                    if (side == HVRHandSide.Left)
                    {
                        LeftOculusController = controller;
                    }
                    else
                    {
                        RightOculusController = controller;
                    }
                }
#endif

                break;

            case InputSDK.SteamVR:

#if HVR_STEAMVR
                controller = side == HVRHandSide.Left ? LeftSteamController : RightSteamController;
                if (!controller)
                {
                    var steamController = gameObject.AddComponent <HVRSteamVRController>();
                    controller = steamController;
                    if (side == HVRHandSide.Left)
                    {
                        LeftSteamController = steamController;
                    }
                    else
                    {
                        RightSteamController = steamController;
                    }
                }
#endif
                break;

            case InputSDK.InputSystem:
#if ENABLE_INPUT_SYSTEM
                controller = side == HVRHandSide.Left ? LeftInputSystemController : RightInputSystemController;
                if (!controller)
                {
                    var inputSystemController = gameObject.AddComponent <HVRInputSystemController>();
                    controller = inputSystemController;
                    if (side == HVRHandSide.Left)
                    {
                        LeftInputSystemController = inputSystemController;
                    }
                    else
                    {
                        RightInputSystemController = inputSystemController;
                    }
                }
#endif
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (OverrideDeadzone)
            {
                deadZone = DeadzoneOverride;
            }

            if (controller != null)
            {
                controller.XRNode             = side == HVRHandSide.Left ? XRNode.LeftHand : XRNode.RightHand;
                controller.ThumbstickDeadZone = deadZone;
                controller.Side           = side;
                controller.InputMap       = inputMap;
                controller.enabled        = true;
                controller.ControllerType = controllerType;
            }

            controller.FingerSettings = FingerSettings;

            return(controller);
        }