Skip to content

Commit f492e5e

Browse files
committed
Add ability to identify ViveFlowPhoneController
Also add identifying ViveTracker3 Also fix some naming typo Also rename WaveCRControllerLeft to ViveFocus3ControllerLeft Also disable warning for compatibility (may cause error if using old version of XR package) XRManagerSettings.loaders => XRManagerSettings.activeLoaders
1 parent bda6d6e commit f492e5e

File tree

6 files changed

+45
-24
lines changed

6 files changed

+45
-24
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ protected override void UpdateNewConnectedInputDevice(IVRModuleDeviceStateRW sta
8484
updateFunc = UpdateViveCosmosControllerState;
8585
break;
8686
case VRModuleDeviceModel.ViveTracker:
87+
case VRModuleDeviceModel.ViveTracker3:
8788
updateFunc = UpdateViveTrackerState;
8889
break;
8990
case VRModuleDeviceModel.OculusTouchLeft:
@@ -110,13 +111,14 @@ protected override void UpdateNewConnectedInputDevice(IVRModuleDeviceStateRW sta
110111
updateFunc = UpdateViveFocusChirpControllerState;
111112
break;
112113
case VRModuleDeviceModel.ViveFocusFinch:
114+
case VRModuleDeviceModel.ViveFlowPhoneController:
113115
updateFunc = UpdateViveFocusFinchControllerState;
114116
break;
115117
case VRModuleDeviceModel.KhronosSimpleController:
116118
updateFunc = UpdateKhronosSimpleControllerState;
117119
break;
118-
case VRModuleDeviceModel.WaveCRControllerLeft:
119-
case VRModuleDeviceModel.WaveCRControllerRight:
120+
case VRModuleDeviceModel.ViveFocus3ControllerLeft:
121+
case VRModuleDeviceModel.ViveFocus3ControllerRight:
120122
updateFunc = UpdateWaveCRControllerState;
121123
break;
122124
default:
@@ -209,7 +211,7 @@ private void UpdateUnknownControllerState(IVRModuleDeviceStateRW state, InputDev
209211
state.SetButtonTouch(VRModuleRawButton.Grip, gripButton);
210212
state.SetButtonTouch(VRModuleRawButton.Touchpad, primary2DAxisTouch);
211213
state.SetButtonTouch(VRModuleRawButton.Joystick, secondary2DAxisTouch);
212-
214+
213215
state.SetAxisValue(VRModuleRawAxis.Trigger, triggerValue);
214216
state.SetAxisValue(VRModuleRawAxis.CapSenseGrip, gripValue);
215217
state.SetAxisValue(VRModuleRawAxis.TouchpadX, primary2DAxisValue.x);
@@ -245,7 +247,7 @@ private void UpdateViveControllerState(IVRModuleDeviceStateRW state, InputDevice
245247
{
246248
bool systemButton = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage<bool>("SystemButton")); // Always false
247249
float grip = GetDeviceFeatureValueOrDefault(device, CommonUsages.grip); // 0 or 1
248-
250+
249251
state.SetButtonPress(VRModuleRawButton.System, systemButton);
250252
state.SetAxisValue(VRModuleRawAxis.CapSenseGrip, grip);
251253
}
@@ -423,9 +425,9 @@ private void UpdateWMRControllerState(IVRModuleDeviceStateRW state, InputDevice
423425
bool menuButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.menuButton);
424426
bool triggerButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.triggerButton);
425427
bool gripButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.gripButton);
426-
428+
427429
float trigger = GetDeviceFeatureValueOrDefault(device, CommonUsages.trigger);
428-
430+
429431
state.SetButtonPress(VRModuleRawButton.ApplicationMenu, menuButton);
430432
state.SetButtonPress(VRModuleRawButton.Trigger, triggerButton);
431433
state.SetButtonPress(VRModuleRawButton.Grip, gripButton);

Assets/HTC.UnityPlugin/VRModule/VRModuleBase.cs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ protected enum DefaultModuleOrder
3636

3737
private static readonly Regex s_viveRgx = new Regex("^.*(vive|htc).*$", REGEX_OPTIONS);
3838
private static readonly Regex s_viveCosmosRgx = new Regex("^.*(cosmos).*$", REGEX_OPTIONS);
39+
private static readonly Regex s_ver3Rgx = new Regex("^.*3.0.*$", REGEX_OPTIONS);
3940
private static readonly Regex s_oculusRgx = new Regex("^.*(oculus|quest).*$", REGEX_OPTIONS);
4041
private static readonly Regex s_indexRgx = new Regex("^.*(index|knuckles).*$", REGEX_OPTIONS);
4142
private static readonly Regex s_knucklesRgx = new Regex("^.*(knu_ev1).*$", REGEX_OPTIONS);
@@ -49,16 +50,23 @@ protected enum DefaultModuleOrder
4950

5051
private struct WVRCtrlProfile
5152
{
53+
public Regex reg;
5254
public VRModuleDeviceModel model;
5355
public VRModuleInput2DType input2D;
5456
}
55-
private static Dictionary<string, WVRCtrlProfile> m_wvrModels = new Dictionary<string, WVRCtrlProfile>
57+
58+
private static WVRCtrlProfile[] s_wvrCtrlProfiles = new WVRCtrlProfile[]
5659
{
57-
{ "WVR_CONTROLLER_FINCH3DOF_2_0", new WVRCtrlProfile() { model = VRModuleDeviceModel.ViveFocusFinch, input2D = VRModuleInput2DType.TouchpadOnly } },
58-
{ "WVR_CONTROLLER_ASPEN_MI6_1", new WVRCtrlProfile() { model = VRModuleDeviceModel.ViveFocusChirp, input2D = VRModuleInput2DType.TouchpadOnly } },
59-
{ "WVR_CONTROLLER_ASPEN_XA_XB", new WVRCtrlProfile() { model = VRModuleDeviceModel.ViveFocusChirp, input2D = VRModuleInput2DType.TouchpadOnly } },
60-
{ "WVR_CR_Right_001", new WVRCtrlProfile() { model = VRModuleDeviceModel.WaveCRControllerRight, input2D = VRModuleInput2DType.JoystickOnly } },
61-
{ "WVR_CR_Left_001", new WVRCtrlProfile() { model = VRModuleDeviceModel.WaveCRControllerLeft, input2D = VRModuleInput2DType.JoystickOnly } },
60+
// WVR_CONTROLLER_FINCH3DOF_2_0_PAC_20_9_DARK
61+
new WVRCtrlProfile { reg = new Regex("^.*(pac).*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFlowPhoneController, input2D = VRModuleInput2DType.TouchpadOnly },
62+
// WVR_CONTROLLER_FINCH3DOF_2_0
63+
new WVRCtrlProfile { reg = new Regex("^.*(finch).*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFocusFinch, input2D = VRModuleInput2DType.TouchpadOnly },
64+
// WVR_CONTROLLER_ASPEN_MI6_1, WVR_CONTROLLER_ASPEN_XA_XB
65+
new WVRCtrlProfile { reg = new Regex("^.*(aspen).*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFocusChirp, input2D = VRModuleInput2DType.TouchpadOnly },
66+
// WVR_CR_Left_001
67+
new WVRCtrlProfile { reg = new Regex("^.*(cr).(left)*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFocus3ControllerLeft, input2D = VRModuleInput2DType.TouchpadOnly },
68+
// WVR_CR_Right_001
69+
new WVRCtrlProfile { reg = new Regex("^.*(cr).(right)*$", REGEX_OPTIONS), model = VRModuleDeviceModel.ViveFocus3ControllerRight, input2D = VRModuleInput2DType.TouchpadOnly },
6270
};
6371

6472
public bool isActivated { get; private set; }
@@ -186,7 +194,14 @@ protected static void SetupKnownDeviceModel(IVRModuleDeviceStateRW deviceState)
186194
}
187195
return;
188196
case VRModuleDeviceClass.GenericTracker:
189-
deviceState.deviceModel = VRModuleDeviceModel.ViveTracker;
197+
if (s_ver3Rgx.IsMatch(deviceState.modelNumber))
198+
{
199+
deviceState.deviceModel = VRModuleDeviceModel.ViveTracker3;
200+
}
201+
else
202+
{
203+
deviceState.deviceModel = VRModuleDeviceModel.ViveTracker;
204+
}
190205
return;
191206
case VRModuleDeviceClass.TrackingReference:
192207
deviceState.deviceModel = VRModuleDeviceModel.ViveBaseStation;
@@ -362,12 +377,12 @@ protected static void SetupKnownDeviceModel(IVRModuleDeviceStateRW deviceState)
362377
return;
363378
case VRModuleDeviceClass.Controller:
364379
{
365-
foreach (var p in m_wvrModels)
380+
foreach (var p in s_wvrCtrlProfiles)
366381
{
367-
if (deviceState.modelNumber.Contains(p.Key))
382+
if (p.reg.IsMatch(deviceState.modelNumber))
368383
{
369-
deviceState.deviceModel = p.Value.model;
370-
deviceState.input2DType = p.Value.input2D;
384+
deviceState.deviceModel = p.model;
385+
deviceState.input2DType = p.input2D;
371386
return;
372387
}
373388
}

Assets/HTC.UnityPlugin/VRModule/VRModuleDeviceState.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ public enum VRModuleDeviceModel
6262
OculusTrackedHandLeft,
6363
OculusTrackedHandRight,
6464
KhronosSimpleController,
65-
WaveCRControllerLeft,
66-
WaveCRControllerRight,
65+
ViveFocus3ControllerLeft,
66+
ViveFocus3ControllerRight,
67+
[HideInInspector, Obsolete("Use ViveFocus3ControllerLeft instead.")]
68+
WaveCRControllerLeft = ViveFocus3ControllerLeft,
69+
[HideInInspector, Obsolete("Use ViveFocus3ControllerRight instead.")]
70+
WaveCRControllerRight = ViveFocus3ControllerRight,
6771
ViveTracker3,
72+
ViveFlowPhoneController,
6873
}
6974

7075
public enum VRModuleRawButton
@@ -158,8 +163,8 @@ public enum VRModuleInput2DType
158163
JoystickOnly = ThumbstickOnly,
159164
}
160165

161-
internal class VRModuleDeviceClassReslver : EnumToIntResolver<VRModuleDeviceClass> { public override int Resolve(VRModuleDeviceClass e) { return (int)e; } }
162-
internal class VRModuleDeviceModelReslver : EnumToIntResolver<VRModuleDeviceModel> { public override int Resolve(VRModuleDeviceModel e) { return (int)e; } }
166+
internal class VRModuleDeviceClassResolver : EnumToIntResolver<VRModuleDeviceClass> { public override int Resolve(VRModuleDeviceClass e) { return (int)e; } }
167+
internal class VRModuleDeviceModelResolver : EnumToIntResolver<VRModuleDeviceModel> { public override int Resolve(VRModuleDeviceModel e) { return (int)e; } }
163168
internal class VRModuleRawButtonReslver : EnumToIntResolver<VRModuleRawButton> { public override int Resolve(VRModuleRawButton e) { return (int)e; } }
164169
internal class VRModuleRawAxisReslver : EnumToIntResolver<VRModuleRawAxis> { public override int Resolve(VRModuleRawAxis e) { return (int)e; } }
165170
internal class VRModuleInput2DTypeReslver : EnumToIntResolver<VRModuleInput2DType> { public override int Resolve(VRModuleInput2DType e) { return (int)e; } }

Assets/HTC.UnityPlugin/VRModule/VRModuleDeviceState.cs.meta

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Editor/XRPluginManagementUtils.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//========= Copyright 2016-2021, HTC Corporation. All rights reserved. ===========
22

3+
#pragma warning disable 0618
34
using System.IO;
45
using System.Linq;
56
using UnityEngine;

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/ViveRole/RoleMaps/PrimaryHandRole.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ public void DelayRefresh()
105105

106106
public void Refresh()
107107
{
108-
UnityEngine.Debug.Log("Refresh");
109108
UnmappingAll();
110109

111110
unmappedRoles.Reset(this);

0 commit comments

Comments
 (0)