Skip to content

Commit a66c819

Browse files
committed
Fixed a problem with previous swap bindings preventing multiple swaps in a row
1 parent bb38389 commit a66c819

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

Assets/Samples/RebindingUI/RebindActionUI.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,23 +256,22 @@ public void ResetToDefault()
256256
/// <remarks>It is expected that the other control is of a compatible type.</remarks>
257257
/// <param name="other">The other instance to swap binding with.</param>
258258
/// <returns>true if successfully swapped, else false.</returns>
259-
public void Swap(RebindActionUI other)
259+
public void SwapBinding(RebindActionUI other)
260260
{
261261
if (this == other)
262262
return; // Silently ignore any request to swap binding with itself
263263
if (ongoingRebind != null || other.ongoingRebind != null)
264-
return; // Do not allow swapping with ongoing rebinding .
265-
264+
throw new Exception("Cannot swap bindings when interactive rebinding is ongoing");
266265
if (!ResolveActionAndBinding(out var action, out var bindingIndex))
267266
throw new Exception("Failed to resolve action and binding index");
268267
if (!other.ResolveActionAndBinding(out var otherAction, out var otherBindingIndex))
269268
throw new Exception("Failed to resolve action and binding index");
270269

271-
// Apply binding override to target binding
272-
var path = action.bindings[bindingIndex].path;
273-
var otherPath = otherAction.bindings[otherBindingIndex].path;
274-
action.ApplyBindingOverride(bindingIndex, otherPath);
275-
otherAction.ApplyBindingOverride(otherBindingIndex, path);
270+
// Apply binding override to target binding based on swapped effective binding paths.
271+
var effectivePath = action.bindings[bindingIndex].effectivePath;
272+
var otherEffectivePath = otherAction.bindings[otherBindingIndex].effectivePath;
273+
action.ApplyBindingOverride(bindingIndex, otherEffectivePath);
274+
otherAction.ApplyBindingOverride(otherBindingIndex, effectivePath);
276275
}
277276

278277
/// <summary>

Assets/Samples/RebindingUI/RebindingUISampleScene.unity

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,7 +2524,7 @@ MonoBehaviour:
25242524
- m_Target: {fileID: 1627715299}
25252525
m_TargetAssemblyTypeName: UnityEngine.InputSystem.Samples.RebindUI.RebindActionUI,
25262526
Unity.InputSystem.RebindingUI
2527-
m_MethodName: Swap
2527+
m_MethodName: SwapBinding
25282528
m_Mode: 2
25292529
m_Arguments:
25302530
m_ObjectArgument: {fileID: 720160216}
@@ -4031,7 +4031,7 @@ GameObject:
40314031
m_Icon: {fileID: 0}
40324032
m_NavMeshLayer: 0
40334033
m_StaticEditorFlags: 0
4034-
m_IsActive: 0
4034+
m_IsActive: 1
40354035
--- !u!224 &1014357782
40364036
RectTransform:
40374037
m_ObjectHideFlags: 0
@@ -4084,9 +4084,9 @@ MonoBehaviour:
40844084
m_HorizontalOverflow: 0
40854085
m_VerticalOverflow: 1
40864086
m_LineSpacing: 1
4087-
m_Text: In practice, you probably don't want to set up rebinding the sticks like
4088-
this on a gamepad scheme but rather have a "swap sticks" kind of toggle instead.
4089-
The stick bindings here are included mainly for demonstration purposes.
4087+
m_Text: "In practice, you probably don't want to set up rebinding the sticks like
4088+
this on a gamepad scheme but rather have a \"swap sticks\" kind of toggle instead.
4089+
\n\nHere we do both variants for demonstration purposes."
40904090
--- !u!222 &1014357784
40914091
CanvasRenderer:
40924092
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)