Skip to content

Commit 6fa8100

Browse files
committed
change to using the pointer for this and look if the pointer has a previous state and if that was the same
1 parent 47cfc02 commit 6fa8100

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Packages/com.unity.inputsystem/InputSystem/Controls/InputControlExtensions.cs

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

11151115
foreach (var control in eventPtr.EnumerateControls(Enumerate.IgnoreControlsInDefaultState, magnitudeThreshold: magnitude))
11161116
{
1117-
if (!control.HasValueChangeInEvent(eventPtr) && !(control.device is Touchscreen)) // touches can happen to not have a previous state to compare to after the touch started
1117+
// Continue if the control did change in the event or did not have a previous state to compare to.
1118+
var stateInEvent = control.GetStatePtrFromStateEvent(eventPtr);
1119+
if (stateInEvent == null || !control.CompareValue(control.currentStatePtr, stateInEvent))
11181120
continue;
11191121
if (buttonControlsOnly && !control.isButton)
11201122
continue;

0 commit comments

Comments
 (0)