private void InputDevices_deviceConnected(InputDevice device) { XRInput.Log("XR Device connected: " + device.name); if (!ReplaceControllerIfExists(device)) { controllers.Add(device); } UpdateDevice(device, false); }
private void UpdateDevice(InputDevice device, bool removingDevice) { if (device.characteristics.HasFlag(InputDeviceCharacteristics.Controller)) { if (FindExistingController(device, out int index)) { if (!removingDevice) { controllers[index] = device; } else { controllers.Remove(device); } } else { if (!removingDevice) { controllers.Add(device); } } if (device.characteristics.HasFlag(InputDeviceCharacteristics.Left)) { if (!removingDevice) { XRInput.Log("XR Device Left-Hand configued"); handLeft = device; } else { XRInput.Log("XR Device Left-Hand removed"); handLeft = new InputDevice(); } } else if (device.characteristics.HasFlag(InputDeviceCharacteristics.Right)) { if (!removingDevice) { XRInput.Log("XR Device Right-Hand configued"); handLeft = device; } else { XRInput.Log("XR Device Right-Hand removed"); handLeft = new InputDevice(); } } } }
public override void Init() { base.Init(); // make sure OpenVR is init right away EVRInitError e = EVRInitError.None; system = OpenVR.System; if (system == null) { system = OpenVR.Init(ref e); } XRInput.Log("OpenVR version: " + system.GetRuntimeVersion()); }
private void InputDevices_deviceConfigChanged(InputDevice device) { XRInput.Log("XR Device config changed: " + device.name); ReplaceControllerIfExists(device); UpdateDevice(device, false); }
private void InputDevices_deviceDisconnected(InputDevice device) { XRInput.Log("XR Device disconnected: " + device.name); controllers.Remove(device); UpdateDevice(device, true); }
public override void Init() { base.Init(); // make sure OpenVR is init right away EVRInitError e = EVRInitError.None; system = OpenVR.System; if (system == null) { system = OpenVR.Init(ref e); } XRInput.Log("OpenVR version: " + system.GetRuntimeVersion()); // init input system input = OpenVR.Input; string actionsPath; if (XRInput.singleton.steamSDK_InUse) { actionsPath = Path.Combine(Application.dataPath, "StreamingAssets", "SteamVR", "actions.json"); } else { actionsPath = Path.Combine(Application.dataPath, "StreamingAssets", "OpenVR", "vrstudios_actions.json"); } actionsPath = actionsPath.Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar); XRInput.Log($"Loading OpenVR Input actions: '{actionsPath}'"); var error = input.SetActionManifestPath(actionsPath); if (error != EVRInputError.None) { Debug.LogError("Failed: 'SetActionManifestPath': " + error.ToString()); return; } // get hands GetInputSourceHandle("/user/hand/right", ref viveSource_RightHand); GetInputSourceHandle("/user/hand/left", ref viveSource_LeftHand); // get action set actionSets = new VRActiveActionSet_t[1]; if (!GetActionSetHandle("/actions/vrstudios", ref viveActionSetHandle)) { return; } actionSets[0].ulActionSet = viveActionSetHandle; // get object actions (touch) GetActionHandle("/actions/vrstudios/in/bumpertouch", ref viveAction_BumperTouch); GetActionHandle("/actions/vrstudios/in/triggertouch", ref viveAction_TriggerTouch); GetActionHandle("/actions/vrstudios/in/griptouch", ref viveAction_GripTouch); GetActionHandle("/actions/vrstudios/in/menutouch", ref viveAction_MenuTouch); GetActionHandle("/actions/vrstudios/in/touch1", ref viveAction_Touch1); GetActionHandle("/actions/vrstudios/in/touch2", ref viveAction_Touch2); GetActionHandle("/actions/vrstudios/in/joystick1_touch", ref viveAction_Joystick1_Touch); // get object actions (buttons) GetActionHandle("/actions/vrstudios/in/bumperbutton", ref viveAction_BumperButton); GetActionHandle("/actions/vrstudios/in/triggerbutton", ref viveAction_TriggerButton); GetActionHandle("/actions/vrstudios/in/gripbutton", ref viveAction_GripButton); GetActionHandle("/actions/vrstudios/in/menubutton", ref viveAction_MenuButton); GetActionHandle("/actions/vrstudios/in/button1", ref viveAction_Button1); GetActionHandle("/actions/vrstudios/in/button2", ref viveAction_Button2); GetActionHandle("/actions/vrstudios/in/touchpad1_button", ref viveAction_Touchpad1_Button); GetActionHandle("/actions/vrstudios/in/joystick1_button", ref viveAction_Joystick1_Button); // get object actions (grips) GetActionHandle("/actions/vrstudios/in/grip", ref viveAction_Grip); // get object actions (triggers) GetActionHandle("/actions/vrstudios/in/trigger", ref viveAction_Trigger); // get object actions (touchpads) GetActionHandle("/actions/vrstudios/in/touchpad1", ref viveAction_Touchpad1); // get object actions (joysticks) GetActionHandle("/actions/vrstudios/in/joystick1", ref viveAction_Joystick1); // rumble GetActionHandle("/actions/vrstudios/out/haptic_right", ref viveAction_Rumble_RightHand); GetActionHandle("/actions/vrstudios/out/haptic_left", ref viveAction_Rumble_LeftHand); // finish isInit = true; }