Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Assets/Tests/InputSystem/CoreTests_Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,34 @@

Assert.That(callCount, Is.EqualTo(1));
}

[Test]
[Category("Events")]
public void Events_OnAnyButtonPressed_WorksWithTouchControls()
{
InputSystem.settings.defaultButtonPressPoint = 0.5f;

var touch = InputSystem.AddDevice<Touchscreen>();

var callCount = 0;

InputSystem.onAnyButtonPress
.Call(ctrl =>
{
Assert.That(ctrl, Is.SameAs(touch.touches[0].press));
++callCount;
});

Check warning on line 237 in Assets/Tests/InputSystem/CoreTests_Events.cs

View check run for this annotation

Codecov github.com / codecov/patch

Assets/Tests/InputSystem/CoreTests_Events.cs#L234-L237

Added lines #L234 - L237 were not covered by tests

Assert.That(callCount, Is.Zero);

InputSystem.Update();

SetTouch(0,TouchPhase.Began, new Vector2(12,12));

InputSystem.Update();

Assert.That(callCount, Is.EqualTo(1));
}

Check warning on line 248 in Assets/Tests/InputSystem/CoreTests_Events.cs

View check run for this annotation

Codecov github.com / codecov/patch

Assets/Tests/InputSystem/CoreTests_Events.cs#L248

Added line #L248 was not covered by tests

[Test]
[Category("Events")]
Expand Down
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed `buttonSouth` returning the state of the east button (and so on for all the compass named buttons) when using a Nintendo Switch Pro Controller on iOS [ISXB-1632](issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1632)
- Fixed `aButton` returning the state of the east button (and so on for all the letter named buttons) when using a Nintendo Switch Pro Controller on Standalone & iOS [ISXB-1632](issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1632)
- Fixed an issue where `UIToolkit` `ClickEvent` could be fired on Android after device rotation due to inactive touch state being replayed during action initial state checks [UUM-100125](https://jira.unity3d.com/browse/UUM-100125).
- Fixed InputSystem.onAnyButtonPress fails to trigger when the device receives a touch [UUM-137930](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-137930).

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ public static bool HasButtonPress(this InputEventPtr eventPtr, float magnitude =
/// in the devices state memory. For example, in the gamepad state, button north (bit position 4) will be evaluated before button
/// east (bit position 5), so if both buttons were pressed in the given event, button north would be returned.
/// Note that the function returns null if the <paramref name="eventPtr"/> is not a StateEvent or DeltaStateEvent.</remarks>
public static InputControl GetFirstButtonPressOrNull(this InputEventPtr eventPtr, float magnitude = -1, bool buttonControlsOnly = true)
public static unsafe InputControl GetFirstButtonPressOrNull(this InputEventPtr eventPtr, float magnitude = -1, bool buttonControlsOnly = true)
{
if (eventPtr.type != StateEvent.Type && eventPtr.type != DeltaStateEvent.Type)
return null;
Expand All @@ -1114,7 +1114,9 @@ public static InputControl GetFirstButtonPressOrNull(this InputEventPtr eventPtr

foreach (var control in eventPtr.EnumerateControls(Enumerate.IgnoreControlsInDefaultState, magnitudeThreshold: magnitude))
{
if (!control.HasValueChangeInEvent(eventPtr))
// Continue if the control did change in the event or did not have a previous state to compare to.
var stateInEvent = control.GetStatePtrFromStateEvent(eventPtr);
if (stateInEvent == null || !control.CompareValue(control.currentStatePtr, stateInEvent))
continue;
if (buttonControlsOnly && !control.isButton)
continue;
Expand Down