To enable gamepad input for the UI in Unity3D application you can use the CoherentUIGTGamepad
component. It automatically gets your settings from the Input Manager and creates mappings for your gamepads. You can also fine tune the mappings from the component.
If you use third party input processing, you can manually register a gamepad and update its state with the following methods found on Coherent.UIGT.UISystem
:
RegisterGamepad
will tell the system to expect events from a new gamepad with the given description.UpdateGamepadState
will give the system the latest state of the gamepad which consists of how much each button has been pressed and each axis moved.UnregisterGamepad
will remove a gamepad from the system.Keep in mind that gamepads are defined system-wise and not per view. This means that all views share the same gamepads. Although updating the states multiple times per frame is not harmful, there's no reason to do so.
If a view loses focus, it will continue to receive updates. You need to handle that in your JavaScript if this behaviour is undesired.