@@ -34,6 +34,8 @@ namespace UnityEngine.InputSystem.OnScreen
34
34
[ HelpURL ( InputSystem . kDocUrl + "/manual/OnScreen.html#on-screen-sticks" ) ]
35
35
public class OnScreenStick : OnScreenControl , IPointerDownHandler , IPointerUpHandler , IDragHandler
36
36
{
37
+ private const string kDynamicOriginClickable = "DynamicOriginClickable" ;
38
+
37
39
/// <summary>
38
40
/// Callback to handle OnPointerDown UI events.
39
41
/// </summary>
@@ -115,7 +117,7 @@ private void Start()
115
117
if ( m_Behaviour != Behaviour . ExactPositionWithDynamicOrigin ) return ;
116
118
m_PointerDownPos = m_StartPos ;
117
119
118
- var dynamicOrigin = new GameObject ( "DynamicOriginClickable" , typeof ( Image ) ) ;
120
+ var dynamicOrigin = new GameObject ( kDynamicOriginClickable , typeof ( Image ) ) ;
119
121
dynamicOrigin . transform . SetParent ( transform ) ;
120
122
var image = dynamicOrigin . GetComponent < Image > ( ) ;
121
123
image . color = new Color ( 1 , 1 , 1 , 0 ) ;
@@ -283,6 +285,16 @@ private void DrawGizmoCircle(Vector2 center, float radius)
283
285
}
284
286
}
285
287
288
+ private void UpdateDynamicOriginClickableArea ( )
289
+ {
290
+ var dynamicOriginTransform = transform . Find ( kDynamicOriginClickable ) ;
291
+ if ( dynamicOriginTransform )
292
+ {
293
+ var rectTransform = ( RectTransform ) dynamicOriginTransform ;
294
+ rectTransform . sizeDelta = new Vector2 ( m_DynamicOriginRange * 2 , m_DynamicOriginRange * 2 ) ;
295
+ }
296
+ }
297
+
286
298
/// <summary>
287
299
/// The distance from the onscreen control's center of origin, around which the control can move.
288
300
/// </summary>
@@ -297,7 +309,7 @@ public float movementRange
297
309
/// </summary>
298
310
/// <remarks>
299
311
/// This only applies if <see cref="behaviour"/> is set to <see cref="Behaviour.ExactPositionWithDynamicOrigin"/>.
300
- /// When the first press is within this region, then the control will be apprear at that position and and have it's origin of motion placed there.
312
+ /// When the first press is within this region, then the control will appear at that position and have it's origin of motion placed there.
301
313
/// Otherwise, if pressed outside of this region the control will ignore it.
302
314
/// This property defines the radius of the circular region. The center point being defined by the component position in the scene.
303
315
/// </remarks>
@@ -306,15 +318,11 @@ public float dynamicOriginRange
306
318
get => m_DynamicOriginRange ;
307
319
set
308
320
{
321
+ // ReSharper disable once CompareOfFloatsByEqualityOperator
309
322
if ( m_DynamicOriginRange != value )
310
323
{
311
324
m_DynamicOriginRange = value ;
312
- var dynamicOriginGO = GameObject . Find ( "DynamicOriginClickable" ) ;
313
- if ( dynamicOriginGO )
314
- {
315
- var rectTransform = ( RectTransform ) dynamicOriginGO . transform ;
316
- rectTransform . sizeDelta = new Vector2 ( value * 2 , value * 2 ) ;
317
- }
325
+ UpdateDynamicOriginClickableArea ( ) ;
318
326
}
319
327
}
320
328
}
@@ -343,22 +351,28 @@ public bool useIsolatedInputActions
343
351
344
352
[ FormerlySerializedAs ( "movementRange" ) ]
345
353
[ SerializeField ]
354
+ [ Min ( 0 ) ]
346
355
private float m_MovementRange = 50 ;
347
356
348
357
[ SerializeField ]
358
+ [ Tooltip ( "Defines the circular region where the onscreen control may have it's origin placed." ) ]
359
+ [ Min ( 0 ) ]
349
360
private float m_DynamicOriginRange = 100 ;
350
361
351
362
[ InputControl ( layout = "Vector2" ) ]
352
363
[ SerializeField ]
353
364
private string m_ControlPath ;
354
365
355
366
[ SerializeField ]
356
- [ Tooltip ( "Choose how the onscreen stick will move relative to it's origin and the press position." ) ]
367
+ [ Tooltip ( "Choose how the onscreen stick will move relative to it's origin and the press position.\n \n " +
368
+ "RelativePositionWithStaticOrigin: The control's center of origin is fixed. " +
369
+ "The control will begin un-actuated at it's centered position and then move relative to the pointer or finger motion.\n \n " +
370
+ "ExactPositionWithStaticOrigin: The control's center of origin is fixed. The stick will immediately jump to the " +
371
+ "exact position of the click or touch and begin tracking motion from there.\n \n " +
372
+ "ExactPositionWithDynamicOrigin: The control's center of origin is determined by the initial press position. " +
373
+ "The stick will begin un-actuated at this center position and then track the current pointer or finger position." ) ]
357
374
private Behaviour m_Behaviour ;
358
375
359
- [ SerializeField ]
360
- private bool m_ShowRanges ;
361
-
362
376
[ SerializeField ]
363
377
[ Tooltip ( "Set this to true to prevent cancellation of pointer events due to device switching. Cancellation " +
364
378
"will appear as the stick jumping back and forth between the pointer position and the stick center." ) ]
@@ -399,7 +413,7 @@ public Behaviour behaviour
399
413
public enum Behaviour
400
414
{
401
415
/// <summary>The control's center of origin is fixed in the scene.
402
- /// The control will begin unactuated at it's centered position and then move relative to the press motion.</summary>
416
+ /// The control will begin un-actuated at it's centered position and then move relative to the press motion.</summary>
403
417
RelativePositionWithStaticOrigin ,
404
418
405
419
/// <summary>The control's center of origin is fixed in the scene.
@@ -452,7 +466,12 @@ public override void OnInspectorGUI()
452
466
if ( EditorGUILayout . BeginFadeGroup ( m_ShowDynamicOriginOptions . faded ) )
453
467
{
454
468
EditorGUI . indentLevel ++ ;
469
+ EditorGUI . BeginChangeCheck ( ) ;
455
470
EditorGUILayout . PropertyField ( m_DynamicOriginRange ) ;
471
+ if ( EditorGUI . EndChangeCheck ( ) )
472
+ {
473
+ ( ( OnScreenStick ) target ) . UpdateDynamicOriginClickableArea ( ) ;
474
+ }
456
475
EditorGUI . indentLevel -- ;
457
476
}
458
477
EditorGUILayout . EndFadeGroup ( ) ;
0 commit comments