Skip to content

Commit 37d120e

Browse files
smnwttbrekcohPauliusd01
authored
FIX: fixed logic when checking for next composite part in the TreeView (#1925)
* Fixed logic when checking for next composite part in the TreeView * Added test case for multiple bindings per composite part for Vector2 composite type. --------- Co-authored-by: Håkan Sidenvall <[email protected]> Co-authored-by: Paulius Dervinis <[email protected]>
1 parent 01326cb commit 37d120e

File tree

3 files changed

+185
-17
lines changed

3 files changed

+185
-17
lines changed

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9610,6 +9610,165 @@ public void Actions_Vector2Composite_WithKeyboardKeys_CancelOnRelease()
96109610
}
96119611
}
96129612

9613+
[Test]
9614+
[Category("Actions")]
9615+
public void Actions_CanCreateComposite_WithMultipleBindingsPerPart()
9616+
{
9617+
var keyboard = InputSystem.AddDevice<Keyboard>();
9618+
9619+
// Set up classic WASD control and additional arrow key support on the same composite.
9620+
var action = new InputAction();
9621+
action.AddCompositeBinding("Dpad")
9622+
.With("Up", "<Keyboard>/w")
9623+
.With("Down", "<Keyboard>/s")
9624+
.With("Left", "<Keyboard>/a")
9625+
.With("Right", "<Keyboard>/d")
9626+
.With("Up", "<Keyboard>/upArrow")
9627+
.With("Down", "<Keyboard>/downArrow")
9628+
.With("Left", "<Keyboard>/leftArrow")
9629+
.With("Right", "<Keyboard>/rightArrow");
9630+
action.Enable();
9631+
9632+
Vector2? value = null;
9633+
action.performed += ctx => { value = ctx.ReadValue<Vector2>(); };
9634+
9635+
// Up.
9636+
value = null;
9637+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.W));
9638+
InputSystem.Update();
9639+
9640+
Assert.That(value, Is.Not.Null);
9641+
Assert.That(value.Value, Is.EqualTo(Vector2.up));
9642+
9643+
// Up left.
9644+
value = null;
9645+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.W, Key.A));
9646+
InputSystem.Update();
9647+
9648+
Assert.That(value, Is.Not.Null);
9649+
Assert.That(value.Value.x, Is.EqualTo((Vector2.up + Vector2.left).normalized.x).Within(0.00001));
9650+
Assert.That(value.Value.y, Is.EqualTo((Vector2.up + Vector2.left).normalized.y).Within(0.00001));
9651+
9652+
// Left.
9653+
value = null;
9654+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A));
9655+
InputSystem.Update();
9656+
9657+
Assert.That(value, Is.Not.Null);
9658+
Assert.That(value.Value, Is.EqualTo(Vector2.left));
9659+
9660+
// Down left.
9661+
value = null;
9662+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.A, Key.S));
9663+
InputSystem.Update();
9664+
9665+
Assert.That(value, Is.Not.Null);
9666+
Assert.That(value.Value.x, Is.EqualTo((Vector2.left + Vector2.down).normalized.x).Within(0.00001));
9667+
Assert.That(value.Value.y, Is.EqualTo((Vector2.left + Vector2.down).normalized.y).Within(0.00001));
9668+
9669+
// Down.
9670+
value = null;
9671+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.S));
9672+
InputSystem.Update();
9673+
9674+
Assert.That(value, Is.Not.Null);
9675+
Assert.That(value.Value, Is.EqualTo(Vector2.down));
9676+
9677+
// Down right.
9678+
value = null;
9679+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.S, Key.D));
9680+
InputSystem.Update();
9681+
9682+
Assert.That(value, Is.Not.Null);
9683+
Assert.That(value.Value.x, Is.EqualTo((Vector2.down + Vector2.right).normalized.x).Within(0.00001));
9684+
Assert.That(value.Value.y, Is.EqualTo((Vector2.down + Vector2.right).normalized.y).Within(0.00001));
9685+
9686+
// Right.
9687+
value = null;
9688+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.D));
9689+
InputSystem.Update();
9690+
9691+
Assert.That(value, Is.Not.Null);
9692+
Assert.That(value.Value, Is.EqualTo(Vector2.right));
9693+
9694+
// Up right.
9695+
value = null;
9696+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.D, Key.W));
9697+
InputSystem.Update();
9698+
9699+
Assert.That(value, Is.Not.Null);
9700+
Assert.That(value.Value.x, Is.EqualTo((Vector2.right + Vector2.up).normalized.x).Within(0.00001));
9701+
Assert.That(value.Value.y, Is.EqualTo((Vector2.right + Vector2.up).normalized.y).Within(0.00001));
9702+
9703+
// Up.
9704+
value = null;
9705+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.UpArrow));
9706+
InputSystem.Update();
9707+
9708+
Assert.That(value, Is.Not.Null);
9709+
Assert.That(value.Value, Is.EqualTo(Vector2.up));
9710+
9711+
// Up left.
9712+
value = null;
9713+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.UpArrow, Key.LeftArrow));
9714+
InputSystem.Update();
9715+
9716+
Assert.That(value, Is.Not.Null);
9717+
Assert.That(value.Value.x, Is.EqualTo((Vector2.up + Vector2.left).normalized.x).Within(0.00001));
9718+
Assert.That(value.Value.y, Is.EqualTo((Vector2.up + Vector2.left).normalized.y).Within(0.00001));
9719+
9720+
// Left.
9721+
value = null;
9722+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.LeftArrow));
9723+
InputSystem.Update();
9724+
9725+
Assert.That(value, Is.Not.Null);
9726+
Assert.That(value.Value, Is.EqualTo(Vector2.left));
9727+
9728+
// Down left.
9729+
value = null;
9730+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.LeftArrow, Key.DownArrow));
9731+
InputSystem.Update();
9732+
9733+
Assert.That(value, Is.Not.Null);
9734+
Assert.That(value.Value.x, Is.EqualTo((Vector2.left + Vector2.down).normalized.x).Within(0.00001));
9735+
Assert.That(value.Value.y, Is.EqualTo((Vector2.left + Vector2.down).normalized.y).Within(0.00001));
9736+
9737+
// Down.
9738+
value = null;
9739+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.DownArrow));
9740+
InputSystem.Update();
9741+
9742+
Assert.That(value, Is.Not.Null);
9743+
Assert.That(value.Value, Is.EqualTo(Vector2.down));
9744+
9745+
// Down right.
9746+
value = null;
9747+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.DownArrow, Key.RightArrow));
9748+
InputSystem.Update();
9749+
9750+
Assert.That(value, Is.Not.Null);
9751+
Assert.That(value.Value.x, Is.EqualTo((Vector2.down + Vector2.right).normalized.x).Within(0.00001));
9752+
Assert.That(value.Value.y, Is.EqualTo((Vector2.down + Vector2.right).normalized.y).Within(0.00001));
9753+
9754+
// Right.
9755+
value = null;
9756+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.RightArrow));
9757+
InputSystem.Update();
9758+
9759+
Assert.That(value, Is.Not.Null);
9760+
Assert.That(value.Value, Is.EqualTo(Vector2.right));
9761+
9762+
// Up right.
9763+
value = null;
9764+
InputSystem.QueueStateEvent(keyboard, new KeyboardState(Key.RightArrow, Key.UpArrow));
9765+
InputSystem.Update();
9766+
9767+
Assert.That(value, Is.Not.Null);
9768+
Assert.That(value.Value.x, Is.EqualTo((Vector2.right + Vector2.up).normalized.x).Within(0.00001));
9769+
Assert.That(value.Value.y, Is.EqualTo((Vector2.right + Vector2.up).normalized.y).Within(0.00001));
9770+
}
9771+
96139772
[Test]
96149773
[Category("Actions")]
96159774
public void Actions_CanCreateComposite_WithPartsBeingOutOfOrder()

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ however, it has to be formatted properly to pass verification tests.
3838
- Added additional device information when logging the error due to exceeding the maximum number of events processed
3939
set by `InputSystem.settings.maxEventsBytesPerUpdate`. This additional information is available in development builds
4040
only.
41+
- Fixed deletion of last composite part raising an exception. [ISXB-804](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-804)
4142

4243
### Changed
4344
- Changed `DualSenseHIDInputReport` from internal to public visibility

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/Views/ActionsTreeView.cs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -611,30 +611,38 @@ public static List<TreeViewItemData<ActionOrBindingData>> GetActionsAsTreeViewDa
611611

612612
if (serializedInputBinding.isComposite)
613613
{
614+
var isLastBinding = i >= actionBindings.Count - 1;
615+
var hasHiddenCompositeParts = false;
616+
614617
var compositeItems = new List<TreeViewItemData<ActionOrBindingData>>();
615-
var nextBinding = actionBindings[++i];
616-
var hiddenCompositeParts = false;
617-
while (nextBinding.isPartOfComposite)
618+
619+
if (!isLastBinding)
618620
{
619-
var isVisible = ShouldBindingBeVisible(nextBinding, state.selectedControlScheme, state.selectedDeviceRequirementIndex);
620-
if (isVisible)
621+
var nextBinding = actionBindings[++i];
622+
623+
while (nextBinding.isPartOfComposite)
621624
{
622-
var name = GetHumanReadableCompositeName(nextBinding, state.selectedControlScheme, controlSchemes);
623-
compositeItems.Add(new TreeViewItemData<ActionOrBindingData>(GetIdForGuid(new Guid(nextBinding.id), idDictionary),
624-
new ActionOrBindingData(isAction: false, name, actionMapIndex, isComposite: false,
625-
isPartOfComposite: true, GetControlLayout(nextBinding.path), bindingIndex: nextBinding.indexOfBinding, isCut: state.IsBindingCut(actionMapIndex, nextBinding.indexOfBinding))));
625+
var isVisible = ShouldBindingBeVisible(nextBinding, state.selectedControlScheme, state.selectedDeviceRequirementIndex);
626+
if (isVisible)
627+
{
628+
var name = GetHumanReadableCompositeName(nextBinding, state.selectedControlScheme, controlSchemes);
629+
compositeItems.Add(new TreeViewItemData<ActionOrBindingData>(GetIdForGuid(new Guid(nextBinding.id), idDictionary),
630+
new ActionOrBindingData(isAction: false, name, actionMapIndex, isComposite: false,
631+
isPartOfComposite: true, GetControlLayout(nextBinding.path), bindingIndex: nextBinding.indexOfBinding, isCut: state.IsBindingCut(actionMapIndex, nextBinding.indexOfBinding))));
632+
}
633+
else
634+
hasHiddenCompositeParts = true;
635+
636+
if (++i >= actionBindings.Count)
637+
break;
638+
639+
nextBinding = actionBindings[i];
626640
}
627-
else
628-
hiddenCompositeParts = true;
629-
630-
if (++i >= actionBindings.Count)
631-
break;
632641

633-
nextBinding = actionBindings[i];
642+
i--;
634643
}
635-
i--;
636644

637-
var shouldCompositeBeVisible = !(compositeItems.Count == 0 && hiddenCompositeParts); //hide composite if all parts are hidden
645+
var shouldCompositeBeVisible = !(compositeItems.Count == 0 && hasHiddenCompositeParts); //hide composite if all parts are hidden
638646
if (shouldCompositeBeVisible)
639647
bindingItems.Add(new TreeViewItemData<ActionOrBindingData>(GetIdForGuid(inputBindingId, idDictionary),
640648
new ActionOrBindingData(isAction: false, serializedInputBinding.name, actionMapIndex, isComposite: true, isPartOfComposite: false, action.expectedControlType, bindingIndex: serializedInputBinding.indexOfBinding, isCut: state.IsBindingCut(actionMapIndex, serializedInputBinding.indexOfBinding)),

0 commit comments

Comments
 (0)