Skip to content

Commit 5fb5f6a

Browse files
author
lawwong
committed
Fix recognizing Oculus devices in UnityXRModule
1 parent f7b5cb8 commit 5fb5f6a

2 files changed

Lines changed: 27 additions & 40 deletions

File tree

Assets/HTC.UnityPlugin/VRModule/Modules/UnityXRModuleBase.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,26 +149,32 @@ public sealed override void BeforeRenderUpdate()
149149

150150
InputDevices.GetDevices(connectedDevices);
151151

152+
var hmdModelNum = string.Empty;
152153
foreach (var device in connectedDevices)
153154
{
154155
if (!indexMap.TryGetIndex(device, out deviceIndex))
155156
{
157+
string deviceName;
158+
156159
if (indexMap.TryMapAsHMD(device))
157160
{
158161
deviceIndex = VRModule.HMD_DEVICE_INDEX;
159162
EnsureValidDeviceState(deviceIndex, out prevState, out currState);
163+
deviceName = device.name;
164+
hmdModelNum = deviceName + " - ";
160165
}
161166
else
162167
{
163168
// this function will skip VRModule.HMD_DEVICE_INDEX (preserved index for HMD)
164169
deviceIndex = FindAndEnsureUnusedNotHMDDeviceState(out prevState, out currState);
165170
indexMap.MapNonHMD(device, deviceIndex);
171+
deviceName = hmdModelNum + device.name;
166172
}
167173

168174
currState.deviceClass = GetDeviceClass(device.name, device.characteristics);
169-
currState.serialNumber = device.name + " " + device.serialNumber + " " + (int)device.characteristics;
170-
currState.modelNumber = device.name + " (" + device.characteristics + ")";
171-
currState.renderModelName = device.name + " (" + device.characteristics + ")";
175+
currState.serialNumber = deviceName + " " + device.serialNumber + " " + (int)device.characteristics;
176+
currState.modelNumber = deviceName + " (" + device.characteristics + ")";
177+
currState.renderModelName = deviceName + " (" + device.characteristics + ")";
172178

173179
SetupKnownDeviceModel(currState);
174180

Assets/HTC.UnityPlugin/VRModule/VRModuleBase.cs

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ protected enum DefaultModuleOrder
3939
private static readonly Regex s_focus3Rgx = new Regex("focus3", REGEX_OPTIONS);
4040
private static readonly Regex s_ver3Rgx = new Regex("^.*3.0.*$", REGEX_OPTIONS);
4141
private static readonly Regex s_oculusRgx = new Regex("^.*(oculus|quest).*$", REGEX_OPTIONS);
42+
private static readonly Regex s_questRgx = new Regex("(quest)", REGEX_OPTIONS);
43+
private static readonly Regex s_quest2Rgx = new Regex("(quest2|quest 2)", REGEX_OPTIONS);
4244
private static readonly Regex s_indexRgx = new Regex("^.*(index|knuckles).*$", REGEX_OPTIONS);
4345
private static readonly Regex s_knucklesRgx = new Regex("^.*(knu_ev1).*$", REGEX_OPTIONS);
4446
private static readonly Regex s_daydreamRgx = new Regex("^.*(daydream).*$", REGEX_OPTIONS);
@@ -231,58 +233,37 @@ protected static void SetupKnownDeviceModel(IVRModuleDeviceStateRW deviceState)
231233
deviceState.deviceModel = VRModuleDeviceModel.OculusHMD;
232234
return;
233235
case VRModuleDeviceClass.Controller:
234-
if (Application.platform == RuntimePlatform.Android)
235236
{
236-
if (deviceState.modelNumber.Contains("Go"))
237+
var headName = GetDeviceState(HMD_DEVICE_INDEX).modelNumber;
238+
if (s_quest2Rgx.IsMatch(deviceState.modelNumber))
237239
{
238-
deviceState.deviceModel = VRModuleDeviceModel.OculusGoController;
239-
deviceState.input2DType = VRModuleInput2DType.TouchpadOnly;
240+
deviceState.deviceModel = s_leftRgx.IsMatch(deviceState.modelNumber) ? VRModuleDeviceModel.OculusQuest2ControllerLeft : VRModuleDeviceModel.OculusQuest2ControllerRight;
241+
deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
240242
return;
241243
}
242-
else if (s_leftRgx.IsMatch(deviceState.modelNumber))
244+
else if (deviceState.modelNumber.Contains("Rift S") || deviceState.modelNumber.Contains("Quest"))
243245
{
244-
deviceState.deviceModel = VRModuleDeviceModel.OculusQuestControllerLeft;
246+
deviceState.deviceModel = s_leftRgx.IsMatch(deviceState.modelNumber) ? VRModuleDeviceModel.OculusQuestOrRiftSControllerLeft : VRModuleDeviceModel.OculusQuestOrRiftSControllerRight;
245247
deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
246248
return;
247249
}
248-
else if (s_rightRgx.IsMatch(deviceState.modelNumber))
250+
else if (deviceState.modelNumber.Contains("Touch"))
249251
{
250-
deviceState.deviceModel = VRModuleDeviceModel.OculusQuestControllerRight;
252+
deviceState.deviceModel = s_leftRgx.IsMatch(deviceState.modelNumber) ? VRModuleDeviceModel.OculusTouchLeft : VRModuleDeviceModel.OculusTouchRight;
251253
deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
252254
return;
253255
}
254-
}
255-
else
256-
{
257-
if (deviceState.modelNumber.Contains("Rift S") || deviceState.modelNumber.Contains("Quest"))
256+
else if (deviceState.modelNumber.Contains("Go"))
258257
{
259-
if (s_leftRgx.IsMatch(deviceState.modelNumber))
260-
{
261-
deviceState.deviceModel = VRModuleDeviceModel.OculusQuestControllerLeft;
262-
deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
263-
return;
264-
}
265-
else if (s_rightRgx.IsMatch(deviceState.modelNumber))
266-
{
267-
deviceState.deviceModel = VRModuleDeviceModel.OculusQuestControllerRight;
268-
deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
269-
return;
270-
}
258+
deviceState.deviceModel = VRModuleDeviceModel.OculusGoController;
259+
deviceState.input2DType = VRModuleInput2DType.TouchpadOnly;
260+
return;
271261
}
272-
else
262+
else if (deviceState.modelNumber.Contains("Gear"))
273263
{
274-
if (s_leftRgx.IsMatch(deviceState.modelNumber))
275-
{
276-
deviceState.deviceModel = VRModuleDeviceModel.OculusTouchLeft;
277-
deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
278-
return;
279-
}
280-
else if (s_rightRgx.IsMatch(deviceState.modelNumber))
281-
{
282-
deviceState.deviceModel = VRModuleDeviceModel.OculusTouchRight;
283-
deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
284-
return;
285-
}
264+
deviceState.deviceModel = VRModuleDeviceModel.OculusGearVrController;
265+
deviceState.input2DType = VRModuleInput2DType.TouchpadOnly;
266+
return;
286267
}
287268
}
288269
break;

0 commit comments

Comments
 (0)