@@ -102,6 +102,7 @@ public Curve curve
102
102
/// <summary>
103
103
/// Gets or sets the on-screen stick radius in millimeters.
104
104
/// </summary>
105
+ /// <remarks>Physical gamepads analog sticks have mechanical displacements of 7-8 millimeters.</remarks>
105
106
/// <exception cref="ArgumentOutOfRangeException">If attempting to set the stick radius to a negative value.</exception>
106
107
public float stickRadiusMillimeters
107
108
{
@@ -115,6 +116,14 @@ public float stickRadiusMillimeters
115
116
}
116
117
}
117
118
119
+ public Vector2 stickCenter
120
+ {
121
+ get => m_Actuated ? m_StickCenter : m_NormalizedBounds . center ;
122
+ }
123
+
124
+ private Vector2 m_StickCenter ;
125
+ private bool m_Actuated ;
126
+
118
127
[ Header ( "Bounds" ) ]
119
128
[ Tooltip ( "The geometric clipping area shape" ) ]
120
129
[ SerializeField ]
@@ -249,6 +258,9 @@ private void ChangeDevice(Touchscreen current)
249
258
250
259
private void OnGestureEvent ( in GestureEvent gestureEvent )
251
260
{
261
+ // TODO We cannot only use drag for this, we need to also know when it gets "activated" so we
262
+ // can set stick position at that point
263
+
252
264
// For button control, we consider the whole clip region as a button area.
253
265
if ( control is ButtonControl )
254
266
{
@@ -266,12 +278,22 @@ private void OnGestureEvent(in GestureEvent gestureEvent)
266
278
if ( gestureEvent . flags . HasFlag ( GestureEvent . Flags . PhaseStart ) ||
267
279
gestureEvent . flags . HasFlag ( GestureEvent . Flags . PhaseChange ) )
268
280
{
269
- // A DualSense has a mechanical displacement of ~7.4 mm.
270
- // A DualShock has a mechanical displacement of ~6.9 mm.
271
-
272
281
var deltaMillimeters = UnitConverter . PixelsToMillimeters ( gestureEvent . delta ) ;
273
282
var stickRadius = Vector2 . ClampMagnitude ( deltaMillimeters , m_StickRadiusMillimeters ) ;
274
283
value = stickRadius / m_StickRadiusMillimeters ;
284
+
285
+ if ( ! m_Actuated )
286
+ {
287
+ m_Actuated = true ;
288
+ m_StickCenter = new Vector2 ( gestureEvent . start . x / Display . displays [ 0 ] . renderingWidth ,
289
+ gestureEvent . start . y / Display . displays [ 0 ] . renderingHeight ) ;
290
+ //m_StickCenter = gestureEvent.start; // TODO Convert to normalized
291
+ }
292
+ }
293
+ else
294
+ {
295
+ m_StickCenter = m_NormalizedBounds . center ;
296
+ m_Actuated = false ;
275
297
}
276
298
277
299
value = m_Curve . Transform ( value ) ;
0 commit comments