What I want is to browse through a list by using the gamepad leftStick. So, top would lead me to the first element, bottom to the last element, left to the previous element and right to the next element.
It is not complicated to achieve with the new input system but I have 2 problems:
- I often get vertical and horizontal events at the same time
- when I press right and release the left event triggers
For the first issue I have written these 2 functions:
public static bool HasLateral(InputAction.CallbackContext context)
{
if (context.control.device is Gamepad)
{
var gamepad = context.control.device as Gamepad;
return gamepad.leftStick.left.isPressed || gamepad.leftStick.right.isPressed;
}
else
{
return false;
}
}
public static bool HasVertical(InputAction.CallbackContext context)
{
if (context.control.device is Gamepad)
{
var gamepad = context.control.device as Gamepad;
return gamepad.leftStick.up.isPressed || gamepad.leftStick.down.isPressed;
}
else
{
return false;
}
}
that I can use like this:
public void Forward(InputAction.CallbackContext context)
{
if (Globals.HasVertical(context))
{
return;
}
...
}
They do work but they don’t handle the second issue. So I have imagined another way like so:
private bool isBrowsing = false;
private void browsingCanceled()
{
isBrowsing= false;
}
public void Forward()
{
if (isBrowsing)
{
return;
}
isBrowsing= true;
}
Naturally with:
controls.Browsing.Forward.started += context => Forward(context);
controls.Browsing.Forward.canceled += context => browsingCanceled();
The idea is to not consider another event until the active one has canceled.
So, my question is if there is a better way to achieve this result? I have tried using ReadValue() but I didn’t get very far with that. Is there some kind of configuration in the Input System that would let me avoid event collisions without all this code?
ETA: I was hoping to find something that would be ReadValue() based with for example 0.3 left and 0.5 top so I would go for the stick moving top.