Skip to content

Commit 7885737

Browse files
committed
Added ability to also reset all bindings
1 parent 1ba9dba commit 7885737

File tree

3 files changed

+746
-1
lines changed

3 files changed

+746
-1
lines changed

Assets/Samples/RebindingUI/RebindActionUI.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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]

Assets/Samples/RebindingUI/RebindActionUIEditor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ protected void OnEnable()
2222
m_RebindOverlayProperty = serializedObject.FindProperty("m_RebindOverlay");
2323
m_RebindTextProperty = serializedObject.FindProperty("m_RebindText");
2424
m_RebindInfoProperty = serializedObject.FindProperty("m_RebindInfo");
25+
m_RebindCancelButtonProperty = serializedObject.FindProperty("m_RebindCancelButton");
2526
m_UpdateBindingUIEventProperty = serializedObject.FindProperty("m_UpdateBindingUIEvent");
2627
m_RebindStartEventProperty = serializedObject.FindProperty("m_RebindStartEvent");
2728
m_RebindStopEventProperty = serializedObject.FindProperty("m_RebindStopEvent");
@@ -64,6 +65,7 @@ public override void OnInspectorGUI()
6465
EditorGUILayout.PropertyField(m_RebindOverlayProperty);
6566
EditorGUILayout.PropertyField(m_RebindTextProperty);
6667
EditorGUILayout.PropertyField(m_RebindInfoProperty);
68+
EditorGUILayout.PropertyField(m_RebindCancelButtonProperty);
6769
}
6870

6971
// Events section.
@@ -158,6 +160,7 @@ protected void RefreshBindingOptions()
158160
private SerializedProperty m_RebindOverlayProperty;
159161
private SerializedProperty m_RebindTextProperty;
160162
private SerializedProperty m_RebindInfoProperty;
163+
private SerializedProperty m_RebindCancelButtonProperty;
161164
private SerializedProperty m_RebindStartEventProperty;
162165
private SerializedProperty m_RebindStopEventProperty;
163166
private SerializedProperty m_UpdateBindingUIEventProperty;

0 commit comments

Comments
 (0)