-
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Please refer to the Installation Guide for instructions on how to add InputLayers to your unity project.
InputLayers is a system built on top of Unity's native Input System. More specifically, it is meant to extend the functionality and usability of Input Actions (referred to as InputActions across this documentation).
The following documentation and accompanying guides require a basic understanding of the InputActions system and how it is configured/used. I will try to be as clear as possible, but I strongly recommend that you first familiarize yourself with InputActions before proceding.
At its core, InputLayers is about letting you easily have multiple systems/UIs/controllers/… react to the same InputAction without:
- Having to manually enable/disable input handling for one system if another has taken over.
- Having to create and configure dozens of ActionMaps with the same InputActions assigned to them just to ensure manage inputs for all your systems/UIs/controllers/…
- Risking the integrity of your input system anytime a new system or UI is added to the game.
To achieve this, InputLayers lets you configure Layers sorted into Priorities using a dedicated editor window.
You then use LayeredActions which belong to a specific Layer in place of the default InputActions.
Each LayeredAction points to a specific InputActon you have created in the default UI Builder editor window, and will react to the InputAction being triggered.
However, the LayeredAction will only register the input and take effect if the Layer it is attached to is active.
And finally, only one Layer can be active at any given time. This works using a simple stack system in which the last layer to have been activated is the only one that can register inputs; and whenever a layer is disabled, the previous layer in the stack takes over.
Priorities simply let you ensure that some layers always take priority over others, regardless of when they were activated. In essence, each priority has its own stack of active layers.
The best way to understand how this works and how it can be used is through examples. Let's start with a simple example that doesn't take Priorities into account:
Note: This example is illustrated in the `IL_Sample_Basic` example scene available as an optional element of the InputLayers package.
Let's imagine a simple UI with 2 main components:
- A simple element that can be interacted with; let's say a circle that appears and disappears when the
Enterkey is pressed. - A main menu that can be opened/closed using the
Escapekey, and which contains a single option that can be interacted with using theEnterkey.
In a "dumb" implementation of this system, if the same InputAction is used for toggling the circle and for activating the option in the main menu; then if the menu is open and no extra safeguard is put in place, the Enter key would both toggle the circle and activate the menu option.
Now let's configure 2 layers using InputLayers:
-
Base, the layer we use for our base interactions (here, toggling the circle and opening the menu). -
Popup, the layer that will handle inputs for when the menu is open.
Since LayeredActions are only active when their corresponding layer is active (on top of the stack), we simply have to:
- Start with the Base layer active (using the
Start()method somewhere in our code). - Have the actions to open/close our menu respectively enable/disable our
Popuplayer. - Handle toggling the circle using the
Baselayer. - Handle activating the menu option using the
Popuplayer. - Make sure that the action to open/close the menu exists both in the
BaseandPopuplayers, so it can be both opened and closed.
This will ensure that pressing the Enter key will only affect the systems relevant to the system/UI that is currently visible on screen.
If you have any questions or need help understanding these core concepts, feel free to start a discussion.
InputLayers is designed to work great whether you prefer using C# directly, or using the unity inspector.
Here, I will go over the basic components of using InputLayers in both scenarios:
WIP
WIP
- WIP
- WIP
👉🏻 Download InputLayers on the Unity Asset Store!