@@ -101,6 +101,15 @@ public Text rebindInfo
101101 set => m_RebindInfo = value ;
102102 }
103103
104+ /// <summary>
105+ /// Optional button to manually cancel rebinding while waiting.
106+ /// </summary>
107+ public Button rebindCancelButton
108+ {
109+ get => m_RebindCancelButton ;
110+ set => m_RebindCancelButton = value ;
111+ }
112+
104113 /// <summary>
105114 /// Optional UI that is activated when an interactive rebind is started and deactivated when the rebind
106115 /// is finished. This is normally used to display an overlay over the current UI while the system is
@@ -272,6 +281,10 @@ private void PerformInteractiveRebind(InputAction action, int bindingIndex, bool
272281
273282 void CleanUp ( )
274283 {
284+ // Restore monitoring cancel button clicks
285+ if ( m_RebindCancelButton != null )
286+ m_RebindCancelButton . onClick . RemoveListener ( CancelRebind ) ;
287+
275288 m_RebindOperation ? . Dispose ( ) ;
276289 m_RebindOperation = null ;
277290
@@ -346,6 +359,12 @@ void CleanUp()
346359 m_RebindText . text = text ;
347360 }
348361
362+ // Optionally allow canceling rebind via a button if it applicable for the use-case
363+ if ( m_RebindCancelButton != null )
364+ {
365+ m_RebindCancelButton . onClick . AddListener ( CancelRebind ) ;
366+ }
367+
349368 // Update rebind overlay information, if we have one.
350369 if ( m_RebindInfo != null )
351370 {
@@ -381,6 +400,11 @@ private void UpdateRebindInfo(double now)
381400 m_LastRemainingTimeoutSeconds = remainingTimeoutWholeSeconds ;
382401 }
383402
403+ private void CancelRebind ( )
404+ {
405+ m_RebindOperation ? . Cancel ( ) ;
406+ }
407+
384408 protected void Update ( )
385409 {
386410 if ( m_RebindInfo != null )
@@ -467,6 +491,10 @@ private static void OnActionChange(object obj, InputActionChange change)
467491 [ SerializeField ]
468492 private Text m_RebindInfo ;
469493
494+ [ Tooltip ( "Optional cancellation UI button for rebinding overlay." ) ]
495+ [ SerializeField ]
496+ private Button m_RebindCancelButton ;
497+
470498 [ Tooltip ( "Event that is triggered when the way the binding is display should be updated. This allows displaying "
471499 + "bindings in custom ways, e.g. using images instead of text." ) ]
472500 [ SerializeField ]
0 commit comments