/// <summary> /// Looks for a matching child and position it accordingly. /// </summary> private void PositionModel(KeyboardModel model) { var keyboardModel = transform.Find(model.ToString("G")); Pose keyboardLocalPose; if (KeyboardModelPose.TryGetValue(model, out keyboardLocalPose)) { keyboardModel.localPosition = keyboardLocalPose.position; keyboardModel.localRotation = keyboardLocalPose.rotation; } }
/// <summary> /// Gets the openvr device id of the first tracked device whose product id /// corresponds to the required keyboard model. Returns true if such a /// device could be found. /// </summary> /// <param name="model">The keyboard model to look for.</param> /// <param name="deviceId">The id of the first device found if the function /// returned true, -1 otherwise.</param> /// <returns>True if a device could be found, false otherwise.</returns> private bool GetFirstKeyboard(KeyboardModel model, out int deviceId) { // KeyboardModel as a 4-digit hex string pid = "0x" + model.ToString("X").Substring(4); var system = OpenVR.System; if (system != null) { for (uint i = 0; i < OpenVR.k_unMaxTrackedDeviceCount; i++) { // check if a model number exists for device i var error = ETrackedPropertyError.TrackedProp_Success; var capacity = system.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_ModelNumber_String, null, 0, ref error); if (capacity <= 1) { continue; } // get that model number var modelNumber = new System.Text.StringBuilder((int)capacity); system.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_ModelNumber_String, modelNumber, capacity, ref error); // compare against required one // note: a proper regex could be used here to avoid corner cases if (modelNumber.ToString().Contains(logitechVid) && modelNumber.ToString().Contains(pid)) { deviceId = (int)i; return(true); } } } else { Debug.LogError("SteamVR likely not initialized, cannot look for a tracked keyboard."); } deviceId = -1; return(false); }