This repository provides an event-driven input management system for Unity using the Unity Input System. It simplifies input handling by exposing events for various gamepad controls, allowing developers to subscribe and react to inputs efficiently.
The input action map is created for gamepad primarily. Keyboard binding are added but require custom mapping and configuration depending on your input control requirements.
- Event-driven input handling for gamepads.
- Supports all standard controller inputs (buttons, sticks, triggers, and D-pad).
- Simple subscription model for listening to input events.
- Debugging utilities to log inputs in real-time.
Scene-GamepadInputVisualiser- Display active inputs - Gamepad
Scene-InputExample-Gamepad&Keyboard- Debug inputs from Gamepad and Keyboard
Scene-LocalMultiplayer- Example using 'PlayerInputManager' to instantiate multiple players or input devices
Scene-LocalMultiplayerSplitScreen- Example using 'PlayerInputManager' to instantiate multiple players or input devices with split screen
Scene-SinglePlayer-AnyDevice- Example taking input from any device connected
Ensure you have the Unity Input System package installed:
- Open Package Manager (
Window > Package Manager). - Search for Input System and install it.
- Enable the new Input System by going to
Edit > Project Settings > Playerand changing the Active Input Handling toBothorInput System Package.
- Attach the
InputHandlerscript to a GameObject in your scene. - Assign your Input Action Asset in the
InputHandlercomponent (replacePlayerwith the actual action map name in your asset). - The script will automatically subscribe to relevant Unity Input System actions and invoke corresponding events.
To listen for input events, subscribe to them in any script.
using UnityEngine;
public class InputDebugger : MonoBehaviour
{
private void OnEnable()
{
InputHandler.OnButtonSouth += () => Debug.Log("Button South Pressed");
InputHandler.OnLeftStick += (Vector2 input) => Debug.Log($"Left Stick Moved: {input}");
}
private void OnDisable()
{
InputHandler.OnButtonSouth -= () => Debug.Log("Button South Pressed");
InputHandler.OnLeftStick -= (Vector2 input) => Debug.Log($"Left Stick Moved: {input}");
}
}| Input | Event Name |
|---|---|
| Left Stick | OnLeftStick |
| Right Stick | OnRightStick |
| Button South | OnButtonSouth |
| Button North | OnButtonNorth |
| Button West | OnButtonWest |
| Button East | OnButtonEast |
| Left Trigger | OnLeftTrigger |
| Right Trigger | OnRightTrigger |
| Left Trigger Pressed | OnLeftTriggerPressed |
| Right Trigger Pressed | OnRightTriggerPressed |
| Left Shoulder | OnLeftShoulder |
| Right Shoulder | OnRightShoulder |
| Left Stick Press | OnLeftStickPress |
| Right Stick Press | OnRightStickPress |
| D-Pad Left | OnPadLeft |
| D-Pad Right | OnPadRight |
| D-Pad Up | OnPadUp |
| D-Pad Down | OnPadDown |
| Left Stick Left | OnLeftStickLeft |
| Left Stick Right | OnLeftStickRight |
| Left Stick Up | OnLeftStickUp |
| Left Stick Down | OnLeftStickDown |
| Right Stick Left | OnRightStickLeft |
| Right Stick Right | OnRightStickRight |
| Right Stick Up | OnRightStickUp |
| Right Stick Down | OnRightStickDown |
| Start Button | OnButtonStart |
| Select Button | OnButtonSelect |
| Input | Event Name |
|---|---|
| Left Stick | OnLeftStickCanceled |
| Right Stick | OnRightStickCanceled |
| Button South | OnButtonSouthCanceled |
| Button North | OnButtonNorthCanceled |
| Button West | OnButtonWestCanceled |
| Button East | OnButtonEastCanceled |
| Left Trigger | OnLeftTriggerCanceled |
| Right Trigger | OnRightTriggerCanceled |
| Left Trigger Released | OnLeftTriggerReleased |
| Right Trigger Released | OnRightTriggerReleased |
| Left Shoulder | OnLeftShoulderCanceled |
| Right Shoulder | OnRightShoulderCanceled |
| Left Stick Press | OnLeftStickPressCanceled |
| Right Stick Press | OnRightStickPressCanceled |
| D-Pad Left | OnPadLeftCanceled |
| D-Pad Right | OnPadRightCanceled |
| D-Pad Up | OnPadUpCanceled |
| D-Pad Down | OnPadDownCanceled |
| Left Stick Left | OnLeftStickLeftCanceled |
| Left Stick Right | OnLeftStickRightCanceled |
| Left Stick Up | OnLeftStickUpCanceled |
| Left Stick Down | OnLeftStickDownCanceled |
| Right Stick Left | OnRightStickLeftCanceled |
| Right Stick Right | OnRightStickRightCanceled |
| Right Stick Up | OnRightStickUpCanceled |
| Right Stick Down | OnRightStickDownCanceled |
| Start Button | OnButtonStartCanceled |
| Select Button | OnButtonSelectCanceled |
A pre-configured scene, Scene-GamepadInputVisualiser, is included to display gamepad inputs in real-time. Open this scene and run the game to see visual feedback of gamepad inputs.
Feel free to fork, modify, and submit pull requests. Contributions and feedback are always welcome!
This project is open-source and licensed under the MIT License.

