In-game Configuration of Input

Platformer PRO supports the in-game configuration of Input. The Standard Input includes a full implementation of this behaviour and many of the samples include this capability.

 

How it Works

The Input class defines a number of methods for changing the Input Data which binds keys to actions. The implementation of these methods is up to the individual implementing class. 

To perform in-game configuration you simply call the relevant Input method, either form your own code or by using the corresponding UIMenuItems from the Menu System.

Because implementations can be quite different in this section we primarily discuss how the Standard Input supports in-game configuration.

Warning: not all Inputs support in-game configuration. 

Setting a Key

Keys are set by calling the method:

override public bool SetKey(KeyType type, KeyCode keyCode)

This method maps the KeyType to the Unity KeyCode. KeyType must not be an axis.

Setting an Axis 

Keys are set by calling the method:

override public bool SetAxis(KeyType type, string axis, bool reverseAxis)

This method maps the KeyType to the given axis. KeyType must be an axis.

Saving the Current Settings

To save the input data call the method:

override public bool SaveInputData()

 

The Input abstract class does not enforce any definition for "saving". In the StandardInput "saving" means writing the data to PlayerPrefs. 

 

Using the in-built Menu System 

In order to allow the easy creation of a menu for in-game configuration of input you can use the Menu System. The following UIMenuItem types are available:

Item Usage
UIMenuItem_KeyConfig Use this to set the value for a given key. Simply set the KeyType (and optional the action button index if this is for an Action Button).
UIMenuItem_SwitchInputType Load input from the Input Data file. Contains a list of human readable names mapped to file names. Note that data files are expected to be defined in a Resource folder

Configuring the Menu

In order to use the in-game configuration Menu Items you must:

  1. Configure a Menu in your scene (see: ).
  2. Create an Input in your scene (for example add a StandardInput component to a GameObject)
  3. Create a sub-menu for key configuration.
  4. Create KeyConfig menu items for each key that needs to be configured.
  5. Create a SwitchInputType if you want the user to be able to cycle through presets.

See the CommandBro and Pixtroid sample scenes for an example of in-game configuration of input.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk