一个示例:InControl: New Unity GUI

翻译原文: http://www.gallantgames.com/pages/incontrol-new-unity-gui

InControl includes an InControlInputModule component which you can add to the EventSystemgame 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.

InControl包含一个InControlInputModule组件, 你可以把它添加到EventSystem对象上。它是用来替换默认的StandaloneInputModule组件,以将输入事件直接从InControl提供给Unity 4.6中添加的新Unity GUI 现在的UGUI。

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

你可以直接把它拖拽到EventSystem对象上,也可以通过Add Component > Event > InControl Input Module的方式。然后StandaloneInputModule组件就可以移除或disable掉了。

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: SubmitActionCancelAction (both of type PlayerAction) and MoveAction (of type TwoAxisPlayerAction).

默认情况下它跟StandaloneInputModule组件的工作方式相同,除了它从InControl的当前活动设备(InputManager.ActiveDevice)读取。

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.

下面是一个示例脚本 “adapter(适配器)”,它使用带有InControlInputModule的绑定API。当然你也可以使用你项目中的其他行为,而不是此处显示的示例行为。

 

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();
        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();
    }
}

 

你可能感兴趣的:(一个示例:InControl: New Unity GUI)