Skip to content

Commit 71e7b61

Browse files
committed
Updated rebinding UI sample to use new feature (handling policy)
1 parent 9bdd2d2 commit 71e7b61

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

Assets/ActionDebug.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using UnityEngine;
22
using UnityEngine.InputSystem;
3+
using UnityEngine.InputSystem.LowLevel;
34

45
public class ActionDebug : MonoBehaviour
56
{
@@ -8,17 +9,31 @@ public class ActionDebug : MonoBehaviour
89
// Start is called once before the first execution of Update after the MonoBehaviour is created
910
void Start()
1011
{
11-
trigger.action.performed += ActionOnperformed;
12+
trigger.action.performed += ActionOnPerformed;
13+
trigger.action.canceled += ActionOnCanceled;
14+
trigger.action.started += ActionOnStarted;
1215
trigger.action.Enable();
1316
}
1417

15-
private void ActionOnperformed(InputAction.CallbackContext obj)
18+
private void ActionOnStarted(InputAction.CallbackContext obj)
19+
{
20+
Debug.Log("Action Started");
21+
}
22+
23+
private void ActionOnCanceled(InputAction.CallbackContext obj)
24+
{
25+
Debug.Log("Action Canceled");
26+
}
27+
28+
private void ActionOnPerformed(InputAction.CallbackContext obj)
1629
{
1730
Debug.Log("Action Performed");
1831
}
1932

2033
// Update is called once per frame
2134
void Update()
2235
{
36+
if (trigger.action.WasPerformedThisFrame())
37+
Debug.Log("Action Performed (Polled Event)");
2338
}
2439
}

Assets/Samples/RebindingUI/RebindActionUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ void CleanUp()
289289
UpdateBindingDisplay();
290290
CleanUp();
291291
})
292-
.OnMatchWaitForAnother(0.2f)
292+
.WithSuppressedActionPropagation()
293293
.OnComplete(
294294
operation =>
295295
{

Packages/com.unity.inputsystem/InputSystem/Actions/InputActionRebindingExtensions.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,6 +2083,23 @@ public RebindingOperation OnMatchWaitForAnother(float seconds)
20832083
return this;
20842084
}
20852085

2086+
/// <summary>
2087+
/// Ensures state changes are allowed to propagate during rebinding but suppresses action updates.
2088+
/// The default behavior is that state changes are also suppressed during rebinding.
2089+
/// </summary>
2090+
/// <remarks>
2091+
/// This is achieved by temporarily setting <see cref="InputSystem.inputEventHandledPolicy"/> to
2092+
/// <see cref="InputEventHandledPolicy.SuppressActionUpdates" />. This is automatically reverted when
2093+
/// the rebinding operation completes. If the policy is already set to
2094+
/// <see cref="InputEventHandledPolicy.SuppressActionUpdates" />, this method has no effect.
2095+
/// </remarks>
2096+
/// <returns>Reference to this rebinding operation.</returns>
2097+
public RebindingOperation WithSuppressedActionPropagation()
2098+
{
2099+
m_TargetInputEventHandledPolicy = InputEventHandledPolicy.SuppressActionUpdates;
2100+
return this;
2101+
}
2102+
20862103
/// <summary>
20872104
/// Start the rebinding. This should be invoked after the rebind operation has been fully configured.
20882105
/// </summary>
@@ -2107,6 +2124,9 @@ public RebindingOperation Start()
21072124

21082125
m_StartTime = InputState.currentTime;
21092126

2127+
m_SavedInputEventHandledPolicy = InputSystem.inputEventHandledPolicy;
2128+
InputSystem.inputEventHandledPolicy = m_TargetInputEventHandledPolicy;
2129+
21102130
if (m_WaitSecondsAfterMatch > 0 || m_Timeout > 0)
21112131
{
21122132
HookOnAfterUpdate();
@@ -2606,6 +2626,8 @@ private void ResetAfterMatchCompleted()
26062626

26072627
UnhookOnEvent();
26082628
UnhookOnAfterUpdate();
2629+
2630+
InputSystem.inputEventHandledPolicy = m_SavedInputEventHandledPolicy;
26092631
}
26102632

26112633
private void ThrowIfRebindInProgress()
@@ -2654,6 +2676,8 @@ private string GeneratePathForControl(InputControl control)
26542676
private double m_StartTime;
26552677
private float m_Timeout;
26562678
private float m_WaitSecondsAfterMatch;
2679+
private InputEventHandledPolicy m_SavedInputEventHandledPolicy;
2680+
private InputEventHandledPolicy m_TargetInputEventHandledPolicy;
26572681
private InputControlList<InputControl> m_Candidates;
26582682
private Action<RebindingOperation> m_OnComplete;
26592683
private Action<RebindingOperation> m_OnCancel;

0 commit comments

Comments
 (0)