@@ -41,15 +41,21 @@ public enum Axis2DTypes
41
41
public WebXRControllerHand hand = WebXRControllerHand . NONE ;
42
42
43
43
private float trigger ;
44
+ private bool triggerTouched ;
44
45
private float squeeze ;
46
+ private bool squeezeTouched ;
45
47
private float thumbstick ;
48
+ private bool thumbstickTouched ;
46
49
private float thumbstickX ;
47
50
private float thumbstickY ;
48
51
private float touchpad ;
52
+ private bool touchpadTouched ;
49
53
private float touchpadX ;
50
54
private float touchpadY ;
51
55
private float buttonA ;
56
+ private bool buttonATouched ;
52
57
private float buttonB ;
58
+ private bool buttonBTouched ;
53
59
54
60
private WebXRControllerButton [ ] buttons ;
55
61
@@ -102,42 +108,48 @@ private void Awake()
102
108
private void InitButtons ( )
103
109
{
104
110
buttons = new WebXRControllerButton [ 6 ] ;
105
- buttons [ ( int ) ButtonTypes . Trigger ] = new WebXRControllerButton ( trigger == 1 , trigger ) ;
106
- buttons [ ( int ) ButtonTypes . Grip ] = new WebXRControllerButton ( squeeze == 1 , squeeze ) ;
107
- buttons [ ( int ) ButtonTypes . Thumbstick ] = new WebXRControllerButton ( thumbstick == 1 , thumbstick ) ;
108
- buttons [ ( int ) ButtonTypes . Touchpad ] = new WebXRControllerButton ( touchpad == 1 , touchpad ) ;
109
- buttons [ ( int ) ButtonTypes . ButtonA ] = new WebXRControllerButton ( buttonA == 1 , buttonA ) ;
110
- buttons [ ( int ) ButtonTypes . ButtonB ] = new WebXRControllerButton ( buttonB == 1 , buttonB ) ;
111
+ buttons [ ( int ) ButtonTypes . Trigger ] = new WebXRControllerButton ( trigger == 1 , triggerTouched , trigger ) ;
112
+ buttons [ ( int ) ButtonTypes . Grip ] = new WebXRControllerButton ( squeeze == 1 , squeezeTouched , squeeze ) ;
113
+ buttons [ ( int ) ButtonTypes . Thumbstick ] = new WebXRControllerButton ( thumbstick == 1 , thumbstickTouched , thumbstick ) ;
114
+ buttons [ ( int ) ButtonTypes . Touchpad ] = new WebXRControllerButton ( touchpad == 1 , touchpadTouched , touchpad ) ;
115
+ buttons [ ( int ) ButtonTypes . ButtonA ] = new WebXRControllerButton ( buttonA == 1 , buttonATouched , buttonA ) ;
116
+ buttons [ ( int ) ButtonTypes . ButtonB ] = new WebXRControllerButton ( buttonB == 1 , buttonBTouched , buttonB ) ;
111
117
}
112
118
113
119
private void UpdateAllButtons ( )
114
120
{
115
- buttons [ ( int ) ButtonTypes . Trigger ] . UpdateState ( trigger == 1 , trigger ) ;
116
- buttons [ ( int ) ButtonTypes . Grip ] . UpdateState ( squeeze == 1 , squeeze ) ;
117
- buttons [ ( int ) ButtonTypes . Thumbstick ] . UpdateState ( thumbstick == 1 , thumbstick ) ;
118
- buttons [ ( int ) ButtonTypes . Touchpad ] . UpdateState ( touchpad == 1 , touchpad ) ;
119
- buttons [ ( int ) ButtonTypes . ButtonA ] . UpdateState ( buttonA == 1 , buttonA ) ;
120
- buttons [ ( int ) ButtonTypes . ButtonB ] . UpdateState ( buttonB == 1 , buttonB ) ;
121
+ buttons [ ( int ) ButtonTypes . Trigger ] . UpdateState ( trigger == 1 , triggerTouched , trigger ) ;
122
+ buttons [ ( int ) ButtonTypes . Grip ] . UpdateState ( squeeze == 1 , squeezeTouched , squeeze ) ;
123
+ buttons [ ( int ) ButtonTypes . Thumbstick ] . UpdateState ( thumbstick == 1 , thumbstickTouched , thumbstick ) ;
124
+ buttons [ ( int ) ButtonTypes . Touchpad ] . UpdateState ( touchpad == 1 , touchpadTouched , touchpad ) ;
125
+ buttons [ ( int ) ButtonTypes . ButtonA ] . UpdateState ( buttonA == 1 , buttonATouched , buttonA ) ;
126
+ buttons [ ( int ) ButtonTypes . ButtonB ] . UpdateState ( buttonB == 1 , buttonBTouched , buttonB ) ;
121
127
}
122
128
123
129
private void UpdateHandButtons ( )
124
130
{
125
- buttons [ ( int ) ButtonTypes . Trigger ] . UpdateState ( trigger == 1 , trigger ) ;
126
- buttons [ ( int ) ButtonTypes . Grip ] . UpdateState ( squeeze == 1 , squeeze ) ;
131
+ buttons [ ( int ) ButtonTypes . Trigger ] . UpdateState ( trigger == 1 , trigger == 1 , trigger ) ;
132
+ buttons [ ( int ) ButtonTypes . Grip ] . UpdateState ( squeeze == 1 , squeeze == 1 , squeeze ) ;
127
133
}
128
134
129
135
private void ResetAllButtons ( )
130
136
{
131
137
trigger = 0 ;
138
+ triggerTouched = false ;
132
139
squeeze = 0 ;
140
+ squeezeTouched = false ;
133
141
thumbstick = 0 ;
142
+ thumbstickTouched = false ;
134
143
thumbstickX = 0 ;
135
144
thumbstickY = 0 ;
136
145
touchpad = 0 ;
146
+ touchpadTouched = false ;
137
147
touchpadX = 0 ;
138
148
touchpadY = 0 ;
139
149
buttonA = 0 ;
150
+ buttonATouched = false ;
140
151
buttonB = 0 ;
152
+ buttonBTouched = false ;
141
153
if ( buttons ? . Length == 6 )
142
154
{
143
155
UpdateAllButtons ( ) ;
@@ -203,6 +215,23 @@ private void TryUpdateButtons()
203
215
buttonB = buttonPressed ? 1 : 0 ;
204
216
}
205
217
218
+ if ( ! inputDevice . Value . TryGetFeatureValue ( CommonUsages . primaryTouch , out buttonATouched ) )
219
+ {
220
+ buttonATouched = buttonA > 0 ;
221
+ }
222
+ if ( ! inputDevice . Value . TryGetFeatureValue ( CommonUsages . secondaryTouch , out buttonBTouched ) )
223
+ {
224
+ buttonBTouched = buttonB > 0 ;
225
+ }
226
+ if ( ! inputDevice . Value . TryGetFeatureValue ( CommonUsages . primary2DAxisTouch , out thumbstickTouched ) )
227
+ {
228
+ thumbstickTouched = thumbstick > 0 ;
229
+ }
230
+ if ( ! inputDevice . Value . TryGetFeatureValue ( CommonUsages . secondary2DAxisTouch , out touchpadTouched ) )
231
+ {
232
+ touchpadTouched = touchpad > 0 ;
233
+ }
234
+
206
235
if ( buttons ? . Length != 6 )
207
236
{
208
237
InitButtons ( ) ;
@@ -259,6 +288,12 @@ public bool GetButtonUp(ButtonTypes buttonType)
259
288
return buttons [ ( int ) buttonType ] . up ;
260
289
}
261
290
291
+ public bool GetButtonTouched ( ButtonTypes buttonType )
292
+ {
293
+ TryUpdateButtons ( ) ;
294
+ return buttons [ ( int ) buttonType ] . touched ;
295
+ }
296
+
262
297
public float GetButtonIndexValue ( int index )
263
298
{
264
299
TryUpdateButtons ( ) ;
@@ -352,15 +387,21 @@ private void OnControllerUpdate(WebXRControllerData controllerData)
352
387
}
353
388
354
389
trigger = controllerData . trigger ;
390
+ triggerTouched = controllerData . triggerTouched ;
355
391
squeeze = controllerData . squeeze ;
392
+ squeezeTouched = controllerData . squeezeTouched ;
356
393
thumbstick = controllerData . thumbstick ;
394
+ thumbstickTouched = controllerData . thumbstickTouched ;
357
395
thumbstickX = controllerData . thumbstickX ;
358
396
thumbstickY = controllerData . thumbstickY ;
359
397
touchpad = controllerData . touchpad ;
398
+ touchpadTouched = controllerData . touchpadTouched ;
360
399
touchpadX = controllerData . touchpadX ;
361
400
touchpadY = controllerData . touchpadY ;
362
401
buttonA = controllerData . buttonA ;
402
+ buttonATouched = controllerData . buttonATouched ;
363
403
buttonB = controllerData . buttonB ;
404
+ buttonBTouched = controllerData . buttonBTouched ;
364
405
365
406
if ( buttons ? . Length != 6 )
366
407
{
0 commit comments