Skip to content

Commit 110d22c

Browse files
jamrethestonefox
authored andcommitted
fix(SDK): use any joystick with button mappings
Swap the Menu Button (Button Two) and Button One codes: Button One: 3 (left) and 1 (right) Button Two: 2 (left) and 0 (right) Except for the Oculus Remote, which uses: Button One: 0 Button Two: 1 Change default button KeyCodes to come from any joystick.
1 parent e5a6884 commit 110d22c

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

Assets/VRTK/Source/SDK/Unity/SDK_UnityController.cs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,23 @@ Right Trackpad NearTouch 16
7171
*/
7272

7373
protected int[] rightControllerTouchCodes = new int[] { 15, 17, 10, 11 };
74-
protected int[] rightControllerPressCodes = new int[] { 9, 0, 1, 7 };
74+
protected int[] rightControllerPressCodes = new int[] { 9, 1, 0, 7 };
75+
protected int[] rightOculusRemotePressCodes = new int[] { 9, 0, 1, 7 };
7576

7677
protected int[] leftControllerTouchCodes = new int[] { 14, 16, 12, 13 };
77-
protected int[] leftControllerPressCodes = new int[] { 8, 2, 3, 7 };
78+
protected int[] leftControllerPressCodes = new int[] { 8, 3, 2, 7 };
7879

7980
protected ControllerType cachedControllerType = ControllerType.Custom;
8081

8182
protected Dictionary<ButtonTypes, KeyCode?> rightControllerTouchKeyCodes = new Dictionary<ButtonTypes, KeyCode?>()
8283
{
83-
{ ButtonTypes.Trigger, KeyCode.Joystick1Button15 },
84+
{ ButtonTypes.Trigger, KeyCode.JoystickButton15 },
8485
{ ButtonTypes.TriggerHairline, null },
8586
{ ButtonTypes.Grip, null },
8687
{ ButtonTypes.GripHairline, null },
87-
{ ButtonTypes.Touchpad, KeyCode.Joystick1Button17 },
88-
{ ButtonTypes.ButtonOne, KeyCode.Joystick1Button10 },
89-
{ ButtonTypes.ButtonTwo, KeyCode.Joystick1Button11 },
88+
{ ButtonTypes.Touchpad, KeyCode.JoystickButton17 },
89+
{ ButtonTypes.ButtonOne, KeyCode.JoystickButton10 },
90+
{ ButtonTypes.ButtonTwo, KeyCode.JoystickButton11 },
9091
{ ButtonTypes.StartMenu, null }
9192
};
9293

@@ -96,21 +97,21 @@ Right Trackpad NearTouch 16
9697
{ ButtonTypes.TriggerHairline, null },
9798
{ ButtonTypes.Grip, null },
9899
{ ButtonTypes.GripHairline, null },
99-
{ ButtonTypes.Touchpad, KeyCode.Joystick1Button9 },
100-
{ ButtonTypes.ButtonOne, KeyCode.Joystick1Button0 },
101-
{ ButtonTypes.ButtonTwo, KeyCode.Joystick1Button1 },
102-
{ ButtonTypes.StartMenu, KeyCode.Joystick1Button7 }
100+
{ ButtonTypes.Touchpad, KeyCode.JoystickButton9 },
101+
{ ButtonTypes.ButtonOne, KeyCode.JoystickButton1 },
102+
{ ButtonTypes.ButtonTwo, KeyCode.JoystickButton0 },
103+
{ ButtonTypes.StartMenu, KeyCode.JoystickButton7 }
103104
};
104105

105106
protected Dictionary<ButtonTypes, KeyCode?> leftControllerTouchKeyCodes = new Dictionary<ButtonTypes, KeyCode?>()
106107
{
107-
{ ButtonTypes.Trigger, KeyCode.Joystick1Button14 },
108+
{ ButtonTypes.Trigger, KeyCode.JoystickButton14 },
108109
{ ButtonTypes.TriggerHairline, null },
109110
{ ButtonTypes.Grip, null },
110111
{ ButtonTypes.GripHairline, null },
111-
{ ButtonTypes.Touchpad, KeyCode.Joystick1Button16 },
112-
{ ButtonTypes.ButtonOne, KeyCode.Joystick1Button12 },
113-
{ ButtonTypes.ButtonTwo, KeyCode.Joystick1Button13 },
112+
{ ButtonTypes.Touchpad, KeyCode.JoystickButton16 },
113+
{ ButtonTypes.ButtonOne, KeyCode.JoystickButton12 },
114+
{ ButtonTypes.ButtonTwo, KeyCode.JoystickButton13 },
114115
{ ButtonTypes.StartMenu, null }
115116
};
116117

@@ -120,10 +121,10 @@ Right Trackpad NearTouch 16
120121
{ ButtonTypes.TriggerHairline, null },
121122
{ ButtonTypes.Grip, null },
122123
{ ButtonTypes.GripHairline, null },
123-
{ ButtonTypes.Touchpad, KeyCode.Joystick1Button8 },
124-
{ ButtonTypes.ButtonOne, KeyCode.Joystick1Button2 },
125-
{ ButtonTypes.ButtonTwo, KeyCode.Joystick1Button3 },
126-
{ ButtonTypes.StartMenu, KeyCode.Joystick1Button7 }
124+
{ ButtonTypes.Touchpad, KeyCode.JoystickButton8 },
125+
{ ButtonTypes.ButtonOne, KeyCode.JoystickButton3 },
126+
{ ButtonTypes.ButtonTwo, KeyCode.JoystickButton2 },
127+
{ ButtonTypes.StartMenu, KeyCode.JoystickButton7 }
127128
};
128129

129130
private bool settingCaches = false;
@@ -745,7 +746,8 @@ protected virtual void SetControllerButtons(ControllerHand hand)
745746
{
746747
if (hand == ControllerHand.Right)
747748
{
748-
SetControllerButtonValues(ref rightControllerTouchKeyCodes, ref rightControllerPressKeyCodes, validJoystickIndex, rightControllerTouchCodes, rightControllerPressCodes);
749+
var pressCodes = cachedControllerType == ControllerType.Oculus_OculusRemote ? rightOculusRemotePressCodes : rightControllerPressCodes;
750+
SetControllerButtonValues(ref rightControllerTouchKeyCodes, ref rightControllerPressKeyCodes, validJoystickIndex, rightControllerTouchCodes, pressCodes);
749751
}
750752
else
751753
{
@@ -767,6 +769,9 @@ protected virtual void SetCachedControllerType(string givenType)
767769
case "googledaydream":
768770
cachedControllerType = ControllerType.Daydream_Controller;
769771
return;
772+
case "oculus remote":
773+
cachedControllerType = ControllerType.Oculus_OculusRemote;
774+
return;
770775
}
771776

772777
//fallback to fuzzy matching

0 commit comments

Comments
 (0)