-
Notifications
You must be signed in to change notification settings - Fork 88
Gamepad Support
In order to make gamepads easier to manage the plugin comes with a system that allows you to map various gamepads to a single, standardized, set of buttons and axes(modeled after the Xbox controller). The mapping of an arbitrary gamepad layout to the standard layout is done through a script that implements the IGamepadStateAdapter interface. At the moment the plugin ships with three gamepad adapters which can be enabled by adding the respective component on the Input Manager game-object.
The standard layout is modeled after the Xbox controller and contains the following buttons and axes:
- LeftThumbstickX & LeftThumbstickY - Left analog stick.
- RightThumbstickX & RightThumbstickY - Right analog stick.
- DPadX & DPadX - DPad axes. For gamepads where the DPad is a series of buttons the axes are simulated from the button input, same as Digital Axis bindings.
- LeftTrigger & RightTrigger - Trigger axes. For gamepads with buttons instead of analog triggers the triggers are simulated from the button input, same as Digital Axis bindings.
- LeftStick & RightStick - The buttons that work by pressing down on the analog sticks.
- LeftBumper & RightBumper
- DPadUp, DPadDown, DPadRight, DPadLeft - DPad buttons. If the gamepad uses axes instead of buttons for the DPad the buttons will be simulated, same as Analog Button bindings.
- Back & Start
- ActionBottom, ActionRight, ActionLeft, ActionTop - These buttons map to A, B, X and Y respectively on the Xbox controller.
All these values are available in the input editor if you set the binding type to Gamepad Button, Gamepad Analog Button or Gamepad Axis.
This adapter uses the XInput library for gamepad input instead of Unity’s input system. The advantage of this adapter is that you will support any XInput compatible gamepad(including Xbox 360 and Xbox One controllers) and you have access to the vibration feature of these gamepads. This adapter is available only in Standalone Windows builds.
- Make sure you imported the XInput addon. It should be in “Assets/InputManager/Addons/XInput”.
- Select your input manager game-object and add the XInputDotNetAdapter component.
- Go to “Project Settings -> Player -> Other Settings -> Scripting Define Symbols” and add the ENABLE_X_INPUT symbol. The adapter will not work if you skip this step.
- DPad Gravity - The speed at which the simulated DPad axis falls towards neutral.
- DPad Sensitivity - The speed at which the simulated DPad axis moves towards positive or negative value.
- DPad Snap - If enabled, the DPad axis will snap to neutral when you switch direction.
- Ignore Timescale - If enabled, the DPad axes will be simulated using unscaled delta time. Generally you want this to be true otherwise your axes will stop updating when you pause the game.
This adapter uses the Universal Windows Platform libraries for gamepad input instead of Unity’s input system and has support for vibration. This is the recommended solution when you’re building games for Windows Store or Xbox using UWP.
- Make sure you imported the XInput addon. It should be in “Assets/InputManager/Addons/XInput”.
- Select your input manager game-object and add the UWPGamepadAdapter component.
- Go to “Project Settings -> Player -> Other Settings -> Scripting Define Symbols” and add the ENABLE_X_INPUT symbol. The adapter will not work if you skip this step.
- DPad Gravity - The speed at which the simulated DPad axis falls towards neutral.
- DPad Sensitivity - The speed at which the simulated DPad axis moves towards positive or negative value.
- DPad Snap - If enabled, the DPad axis will snap to neutral when you switch direction.
- Ignore Timescale - If enabled, the DPad axes will be simulated using unscaled delta time. Generally you want this to be true otherwise your axes will stop updating when you pause the game.
This adapter is intended as a generic solution for mapping gamepad input to the standard layout and will work on any platform(because it uses Unity’s input system under the hood). Unlike the other adapters this one doesn’t support vibration(trying to set the vibration from a script will not throw an error but it won’t have any effect).
Simply select your input manager game-object and add the GenericGamepadStateAdapter component.
- Gamepad Profile - The gamepad profile contains all the mappings from the gamepad layout to the standard layout. The profile can be changed at runtime from a script so it is possible to write a script that selects a profile based on platform or gamepad name and assigns it to the adapter.
- Joystick Check Frequency(in seconds) - The adapter needs to check periodically if gamepads have been connected or disconnected. This value controls the frequency of those checks. By default it will do it once every second.
- Trigger Gravity - The speed at which the simulated trigger axis falls towards neutral.
- Trigger Sensitivity - The speed at which the simulated trigger axis moves towards positive or negative value.
- DPad Gravity - The speed at which the simulated DPad axis falls towards neutral.
- DPad Sensitivity - The speed at which the simulated DPad axis moves towards positive or negative value.
- DPad Snap - If enabled, the DPad axis will snap to neutral when you switch direction.
- Ignore Timescale - If enabled, the DPad axes will be simulated using unscaled delta time. Generally you want this to be true otherwise your axes will stop updating when you pause the game.
Gamepad profiles store the mappings from a specific gamepad’s layout to the standard layout. To create a gamepad profile, right-click in the project panel and select “Create -> Luminosity -> Input Manager -> Gamepad Profile”. The plugin ships with a few example gamepad profiles(Xbox 360 and Playstation 4) that can be found in “Assets/InputManager/Examples/Common/GamepadProfiles”.
- Name - Display name for the profile. Could be used in an options menu to select between different profiles for example.
- Comment - A description for the profile.
- DPad Type - Whether the gamepad uses axes or buttons for the DPad.
- Trigger Type - Whether the gamepad has analog triggers or buttons.
- Left Stick Button - Mapping for the button that works by pressing the left stick down.
- Right Stick Button - Mapping for the button that works by pressing the right stick down.
- Left Bumper Button - Mapping for left bumper button.
- Right Bumper Button - Mapping for right bumper button.
- Left Trigger Button - Mapping for left trigger button. Only if Trigger Type is set to Button.
- Right Trigger Button - Mapping for right trigger button. Only if Trigger Type is set to Button.
- DPad Up Button - Mapping for DPad Up button. Only if DPad Type is set to Button.
- DPad Down Button - Mapping for DPad Down button. Only if DPad Type is set to Button.
- DPad Left Button - Mapping for DPad Left button. Only if DPad Type is set to Button.
- DPad Right Button - Mapping for DPad Right button. Only if DPad Type is set to Button.
- Back Button - Mapping for Back button.
- Start Button - Mapping for Start button.
- Action Top Button - Mapping for the top action button(Y on Xbox).
- Action Bottom Button - Mapping for the top action button(A on Xbox).
- Action Left Button - Mapping for the top action button(X on Xbox).
- Action Right Button - Mapping for the top action button(B on Xbox).
- Left Stick X Axis - Mapping for left analog stick X axis.
- Left Stick Y Axis - Mapping for left analog stick Y axis.
- Right Stick X Axis - Mapping for right analog stick X axis.
- Right Stick Y Axis - Mapping for right analog stick Y axis.
- Left Trigger Axis - Mapping for left trigger axis. Only if Trigger Type is set to Axis.
- Right Trigger Axis - Mapping for right trigger axis. Only if Trigger Type is set to Axis.
- DPad X Axis - Mapping for DPad X axis. Only if DPad Type is set to Axis.
- DPad Y Axis - Mapping for DPad Y axis. Only if DPad Type is set to Axis.
To test your gamepad profiles you can use the example scene from "Assets/InputManager/Examples/07 - Generic Gamepad Adapter/Scenes". You just need to select the input_manager game-object and replace the gamepad profile in the GenericGamepadStateAdapter component.
If you need to create a custom gamepad adapter start by creating a new component that implements the IGamepadStateAdapter and in Awake or Start assign your custom adapter to GamepadState.Adapter. Look at the existing adapters for more implementation details.
if(GamepadState.Adapter == null)
{
GamepadState.Adapter = this;
}
else
{
Debug.LogWarning("You shouldn't have more than one gamepad adapters in the scene");
}