I'm working on a Unity project for Android TV and Fire TV that utilizes the new input system released in v2019.3.
Fire TV's button mappings in the old system were as follows:
Back KeyCode.Escape
Select (D-Pad Center) KeyCode.JoystickButton0
Left (D-Pad) KeyCode.LeftArrow
Right (D-Pad) KeyCode.RightArrow
Up (D-Pad) KeyCode.UpArrow
Down (D-Pad) KeyCode.DownArrow
I've successfully mapped everything but Select/D-Pad Center with the following Binding Paths in the new system:
Escape [Keyboard]
Right Arrow [Keyboard]
Left Arrow [Keyboard]
Up Arrow [Keyboard]
Down Arrow [Keyboard]
If I map to Any Key [Keyboard]
and implement the following code as the callback, it shows up as key: JoystickButton0
, which matches Amazon's documentation, but doesn't exist as an option in the new system under keyboard binding paths:
public void DebugKey(InputAction.CallbackContext context)
{
foreach(KeyCode vKey in System.Enum.GetValues(typeof(KeyCode))){
if(Input.GetKey(vKey)){
Debug.Log ("key: " + vKey);
}
}
}
I've tried various buttons under Gamepad, Android Gamepad, Joystick, and Android Joystick without any success. Another odd thing is that the Center/D-Pad works fine on UI Buttons without any binding.
What is the proper way to map to the legacy KeyCode.JoystickButtonX naming convention with the new input system?
Thanks!
In New system, the devices are read as HID, the KeyCode is not useful, so if you want to read the status of button of joystick, you could do that:
using UnityEngine.InputSystem;
public Joystick joy;
void Start()
{
joy = Joystick.current;
}
void FixedUpdate()
{
var button2 = joy.allControls[2].IsPressed();
if (button2)
{
Debug.Log("Button2 of current joystick is pushed");
}
}
If you want to map the button0 (in old inputsystem), its now the button1 or trigger
var button1 = joy.allControls[1].IsPressed();
or
var button1 = joy.trigger.IsPressed();
And you could test buttons of more sticks..
void Start()
{
var ListOfJoys = Joystick.all;
joy = Joystick.current;//here current joy is ListOfJoys[1]
otherjoy = ListOfJoys[0];
}
var Buttons = joy.allControls;
if ((Buttons[2] as ButtonControl).wasPressedThisFrame)
{
Debug.Log("b2 pressed during this frame");
}
if ((Buttons[2] as ButtonControl).wasReleasedThisFrame)
{
Debug.Log("b2 released during this frame");
}
if (joy.trigger.wasPressedThisFrame)
{
Debug.Log("trig or button1 pressed during this frame");
}
if (joy.trigger.wasReleasedThisFrame)
{
Debug.Log("trig or button1 released during this fram");
}
if (otherjoy.trigger.wasPressedThisFrame)
{
Debug.Log("otherjoy trigger");
}
the other way is to use the mapping of new system, i have mapped the action press Only
Test1 to button3 of stick
that simplify the code and you could mix event and direct test:
//Newinputsystem is a name of class generated
private Newinputsystem playerAction;
void Awake()
{
playerAction = new Newinputsystem();
playerAction.Player.Test1.performed += ctx => FireTest();
}
void FixedUpdate()
{
if (playerAction.Player.Test1.triggered)
{
Debug.Log("fire!!!");
}
}
public void FireTest()
{
Debug.Log("i am in firetest");
}
private void OnEnable()
{
playerAction.Enable();
}
private void OnDisable()
{
playerAction.Disable();
}
so you could add new action test2 which will be triggered with action release only
for button3...
TO display the HID device, go to menu Window/analysis/input debbugger
you have to see your device (here mine is hotas)
and you click on it and in the tab item HID Descriptor
so i suppose you have selected your device in project setting: