Input Sources

When building a game, there are lots of input solutions to choose from. You could use Unity’s built in Input Manager, my Easy Input asset, or any number of assets on the Asset Store. That means I can’t lock my assets into using just one solution.

The way my assets support any input solution is by wrapping the input solution in an ‘Input Source’. This way, my code can call a function like IsJustPressed and not care if the function uses Unity’s Input Manager, Easy Input, or another input solution. We just care if IsJustPressed returns true or false.

Since all input sources implement my IInputSource interface, it doesn’t matter which input solution you use with my assets. I just care that it’s an input source.

IInputSource

Input sources are wrappers around input solutions that implement the IInputSource interface. This means we can use the IInputSource properties and functions and not care if they are referencing Unity’s Input Manager, Easy Input, or something else.

To learn more about Input Sources, check out this video:

 

All input sources have to implement the IInputSource interface. This means that all input sources support specific properties and functions. Common properties and functions exposed by an input source include:

IsEnabled – Determines if the input source returns user input.

MovementX – Horizontal movement caused by user input. This could come from the AD keys, the left and right arrow keys, the left stick on the Xbox controller, etc.

MovementY – Vertical movement caused by user input. This could come from the WS keys, the up and down arrow keys, the left stick on the Xbox controller, etc.

ViewX – Horizontal mouse movement. Typically, we use this to control the camera rotation and view.

ViewY – Vertical mouse movement. Typically we use this to control the camera pitch and view.

IsJustPressed – Determines if a key, button, or action alias is just pressed. This lasts for a single frame. It’s the moment the button is pressed down.

IsPressed – Determines if a key, button, or action alias is currently pressed.

IsJustReleased – Determines if a key, button, or action alias is just released. This lasts for a single frame. It’s the moment the button stops being pressed.

GetValue – Returns the current value of the input. Typically for a key or button this is 0 (not pressed) or 1 (pressed). However, some input controls like analog sticks provide a range of values.

 

Existing Input Sources

I can’t possible own every input solution on the Asset Store. So, I’m not able to make an input source for each one. However, I have made one for Unity’s Input Manager, Easy Input, and others have created input sources as well.

Unity Input Source – This input source comes for free as a part of any of my assets that require user input.

Easy Input Source – This input source comes as part of the Easy Input asset. Its an advanced input source with additional features.

Rewired Input Source – Built for the Rewired asset and available on the ootii Vault.

Easy Touch 5 Input Source – Built for the Easy Touch 5 asset and available on the ootii Vault.

 

Unity Input Source

I call this ‘Unity Input Source’ and I include it in most of my assets.

By adding this component to an object in your scene…

you can now assign the input source to the ‘Input Source’ property on other objects.

My code will then use this input source to get information about key presses, button presses, etc.

Is Input Enabled – Determines if this input source will return user input.

Is Xbox Enabled – Determines if we’ll get input from an Xbox controller as well.

View Activator – Determines when the ViewX and ViewY properties of the input source returns values. We use the ViewX and ViewY properties to provide mouse movement information that typically changes the camera view. So, this property would determine when we rotate the camera.