How Can We Help?

Usage

With everything set up, you’re ready to use the Easy Input. All you have to do is call one of the access functions on the InputManager.

For example:
To test if the ‘A’ key on the keyboard has just been pressed you’d write this:

if (InputManager.IsJustPressed(EnumInput.A))
{
}

To get how long the ‘B’ button on the Xbox controller has been pressed, you’d write this:

float lElapsedTime = InputManager.PressedElapsedTime(EnumInput.GAMEPAD_1_BUTTON);

To get the screen based ‘x’ position of the mouse, you’d write this:

float lX = InputManager.MouseX;

There’s a bunch more you can do. Check the ‘Code Reference’ for all the capabilities.

 

Action Aliases

Action aliases allow you to setup custom names that you can look for in code. This allows you to map multiple inputs to a single action. It provides for a much cleaner approach and also allows for input settings to be changed at run-time.

For example, Let’s say the player can attack by pressing the left mouse button or pressing ‘X’ on the Xbox controller. You can set up an ‘Action Alias’ by doing this:

InputManager.AddAlias("Attack", EnumInput.MOUSE_LEFT_BUTTON);
InputManager.AddAlias("Attack", EnumInput.GAMEPAD_2_BUTTON);

Aliases can be used like any other input control. That means they can be tested for ‘IsPressed’, ‘IsJustPressed’, etc. They can also have timing data retrieved to determine how long they’ve been pressed.

InputManager.IsJustPressed("Attack");

 

To manage the aliases, use the following functions:

InputManager.AddAlias(string AliasName, int InputID)

Adds a new alias including the name and corresponding input.

 

InputManager.AddAlias(string AliasName, int InputID, int HelperInputID)

Adds a new alias including the name and corresponding input. Also expects a ‘helper’ input. This would be an additional key or button that must be active. In the case of ‘Alt + T’, ‘Alt’ is the helper input.

 

InputManager.RemoveAlias(string AliasName)

Removes all inputs associated with the alias name.

 

InputManager.RemoveAlias(string AliasName, int InputID)

Removes the specific entry that has the matching alias name and input id. All other input IDs associated with the alias remain.

 

Default Action Aliases

Several default aliases exist to support the Movement and View properties of the Easy Input’s InputManager.

Movement

MovementX and MovementY are properties on the InputManager that allow for a simple way to test for movement.

By default, movement is set up to use the Xbox controller’s left stick and/or the WASD keys on the keyboard.

Calling InputManager.MovementX returns a value from -1 to 1. These values correspond to a ‘full move left’ and ‘full move right’.

Internally, it uses the following Action Aliases:

MoveHorizontal, which uses the left stick of the gamepad
_MoveLeftKey, which uses the ‘A’ key of the keyboard
_MoveRightKey, which uses the ‘D’ key of the keyboard

 

Calling InputManager.MovementY returns a value from -1 to 1. These values correspond to a ‘full move backward’ and ‘full move forward’.

Internally, it uses the following Action Aliases:

_MoveVertical, which uses the left stick of the gamepad
_MoveUpKey, which uses the ‘W’ key of the keyboard
_MoveDownKey, which uses the ‘S’ key of the keyboard

 

By using the AddAlias and RemoveAlias function against these aliases, you can modify the defaults. For example, using the following code would also allow the ‘Up Arrow’ keyboard key to be used by the InputManager.MovementY function:

InputManager.AddAlias("_MoveUpKey", EnumInput.UP_ARROW);

 

View

ViewX and ViewY are properties on the InputManager that allow for a simple way to test for camera movement.

By default, camera movement is set up to use the Xbox controller’s right stick and/or the mouse.

Calling InputManager.ViewX returns a value from -1 to 1. These values correspond to a ‘camera move left’ and ‘camera move right’.

Internally, it uses the following Action Alias:

_ViewHorizontal, which uses the right stick of the gamepad

 

Calling InputManager.ViewY returns a value from -1 to 1. These values correspond to a ‘camera move down’ and ‘camera move up’.

Internally, it uses the following Action Aliases:

_ViewVertical, which uses the right stick of the gamepad
_MouseViewEnable, which uses the ‘right button’ button of the mouse

If a value for “_MouseViewEnable” exists, the button must be pressed for the mouse to actually return a value for ViewX or ViewY. If there is no value, simply moving the mouse will change the view.

 

Custom Functions

In addition to testing for values on key or button press, you can also assign custom functions to run. These functions should have the following signature:

float FunctionName()
{
}

You can name the function anything you want, but it can’t have any arguments and needs to return a float. In a simple button, the function would return 0 for ‘false’ or 1 for ‘true’. However, you can return any value you want.

To assign the function, simply make a call like this while registering your Action Aliases:

InputManager.AddAlias("Custom", FunctionName);

To call the function, you can simply make a normal input test like so:

float lValue = InputManager.IsPressed("Custom");

 

Optional

Push Events

Event and message dispatching is a critical part of any game. Message dispatching ensures that game objects are able to communicate in a consistent, reliable, and efficient way. In many cases, pushing input updates to listeners is preferred to polling.

See this link for more information about the Event System – Dispatcher.

If you own the Event System – Dispatcher, you can use the InputManager to push messages to objects instead of forcing them to constantly poll the input state.

To do this, ensure both assets (Easy Input and the Dispatcher) are loaded by your project and uncomment the contents of InputManager.SendEvent.

When the InputManager detects a change in the input state, the messages will be sent.

To listen for events, a game object would simply register with the following syntax:

MessageDispatcher.AddListener(EnumInput. MOUSE_LEFT_BUTTON.ToString(),
EnumInputMessageType.INPUT_JUST_PRESSED, MyMouseClickHandlerFunction);

Note that the raising of the event does NOT mean the event happened on the specific object (ie a mouse click on that object). Only that a mouse click occurred.

See the online documentation for additional details.

 

Integrating with Motion Controller or Camera Controller & Rig

If you’ve purchased the Motion Controller or Adventure Camera & Rig (or both)… thank you! I really appreciate the support!

Easy Input works with both of these assets with one additional step:

Drag the GameObject you added the Easy Input Source too, inside the “Input Source” field.

If it says “Missing Unity Input Manager values. Press the button below to set them up”, go ahead and press the “Setup Input Entries” button.

Another thing to note, when utilizing the other assets there may be some error messages. Do not worry as these errors do not signify anything of major importance but are simply due to being built in Unity 5. Pressing on the clear button should clear them up and you should be ready to go!

For more info on the Motion Controller click here

For more info on the Camera Controller click here

Page Contents