Universal input system

Overview 

Universal input system allows you to forget about specific code for different inputs.
This system works on all platforms supported by Unity3D and support different input sources:

  • AutoChoosing
  • Mouse
  • Keyboard
  • Joystick
  • TouchStick
  • Touching
  • Accelerometer

Along with it we provide easy and useful touch input elements (stick and buttons) those make development for touch-devices much easier. 

How to use

To use Universal input system – you should just:

  • add InputManager script to any game object and
  • choose default input source (from UnputType list)
  • setup which buttons you want to use
  • access to InputManager function GetDirection() or/and buttonsControl list

GetDirection() returns normalized Vector2 (x,y) where x and y– offsets by related axis. buttonsControl [i].isPressed () returns true if button (from buttonsControl list) with index i is pressed.

Please check additional detail below. 

InputManager description

Average structure looks like:

directionControl responsible for direction input (from mouse, sticks, gyroscope etc)

  • Keyboard – contains preset of keys used for direction input from keyboard
  • Touch stick – there game object with touch_Stick component should be attached
  • Accelerometer - here game object with Accelerometer_control component should be attached
  • Input Type - Type of input source

buttonsControl list is responsible for any buttons input (pressed or not). Every element contains info about different buttons those can be used for the same action

  • Caption – Just caption
  • Keyboard – keyboard key
  • Gamepad – Jiystick buttons
  • Touch – input from touch button (game object with touch_Button component should be attached)
  • Mouse – Mouse buttons (0 – Left button, 1 – Right button, etc.) 

Helper scripts for input from touch devices

Along with Universal input system we provide easy and useful touch input elements (with multitouch support) those make development for touch-devices much easier:

  • touch_Button - allows to create touch button (visible only on iOS and Android) and read data from it.
  • touch_Stick - allows to create kind of analog stick (visible only on iOS and Android) and read data from it.
  • Accelerometer_control - allows to read data from gyroscope

Please check additional details and how to use them below:

touch_Button description

Average structure looks like: 

 

To make touch_Button just create GUITexture object and setup its position, size and texture. Setup “Scale on Touch” if you want to have scaling effect in time of touch.

Check “Debug Info” checkbox if you want to bring some useful debug info to the screen. Use function “isTouched()” to get info is element touched or not. 

touch_Stick description

Average structure looks like: 

To make touch_Stick just create GUITexture object and setup its position, size and texture.

  • Read “position” variable to get normalized stick offset from initial position.
  • Setup “Active Area Size” to specify screen-limits (start position is in the center) where stick can be moved. Setup “Scale on Touch” if you want to have scaling effect in time of touch.
  • Check “Debug Info” checkbox if you want to bring some useful debug info to the screen.

Use function “isTouched()” to get info is element touched or not. 

Accelerometer_control description

Average structure is extremely simple. 

Check “Debug Info” checkbox if you want to bring some useful debug info to the screen. To use Accelerometer_control just assign it to any game object.