InControl: New Unity GUI

InControl includes an InControlInputModule component which you can add to the EventSystem game object. It is intended to replace the default StandaloneInputModule component to feed input events directly from InControl to the new Unity GUI added in Unity 4.6.

You can drag it onto the EventSystem game object, or add it via Add Component > Event > InControl Input Module and then disable or remove StandaloneInputModule

By default it works identically to StandaloneInputModule except that it reads from InControl’s current active device (InputManager.ActiveDevice). If you’d like to use it with the new bindings API, you can use set the following properties: SubmitAction, CancelAction (both of type PlayerAction) and MoveAction (of type TwoAxisPlayerAction).

Here is an example “adapter” script that uses the bindings API with InControlInputModule. Of course you might use your actions from elsewhere in your project instead of the example action set shown here.

using UnityEngine;
using InControl;


[RequireComponent( typeof(InControlInputModule) )]
public class InputModuleActionAdapter : MonoBehaviour
{
    public class InputModuleActions : PlayerActionSet
    {
        public PlayerAction Submit;
        public PlayerAction Cancel;
        public PlayerAction Left;
        public PlayerAction Right;
        public PlayerAction Up;
        public PlayerAction Down;
        public PlayerTwoAxisAction Move;


        public InputModuleActions()
        {
            Submit = CreatePlayerAction( "Submit" );
            Cancel = CreatePlayerAction( "Cancel" );
            Left = CreatePlayerAction( "Move Left" );
            Right = CreatePlayerAction( "Move Right" );
            Up = CreatePlayerAction( "Move Up" );
            Down = CreatePlayerAction( "Move Down" );
            Move = CreateTwoAxisPlayerAction( Left, Right, Down, Up );
        }
    }


    InputModuleActions actions;


    void OnEnable()
    {
        CreateActions();

        var inputModule = GetComponent<InControlInputModule>();
        if (inputModule != null)
        {
            inputModule.SubmitAction = actions.Submit;
            inputModule.CancelAction = actions.Cancel;
            inputModule.MoveAction = actions.Move;
        }
    }


    void OnDisable()
    {
        DestroyActions();
    }


    void CreateActions()
    {
        actions = new InputModuleActions();

        actions.Submit.AddDefaultBinding( InputControlType.Action1 );
        actions.Submit.AddDefaultBinding( Key.Space );
        actions.Submit.AddDefaultBinding( Key.Return );

        actions.Cancel.AddDefaultBinding( InputControlType.Action2 );
        actions.Cancel.AddDefaultBinding( Key.Escape );

        actions.Up.AddDefaultBinding( InputControlType.LeftStickUp );
        actions.Up.AddDefaultBinding( Key.UpArrow );

        actions.Down.AddDefaultBinding( InputControlType.LeftStickDown );
        actions.Down.AddDefaultBinding( Key.DownArrow );

        actions.Left.AddDefaultBinding( InputControlType.LeftStickLeft );
        actions.Left.AddDefaultBinding( Key.LeftArrow );

        actions.Right.AddDefaultBinding( InputControlType.LeftStickRight );
        actions.Right.AddDefaultBinding( Key.RightArrow );
    }


    void DestroyActions()
    {
        actions.Destroy();
    }
}