[UNITY]2DRPG開発日誌 #45 InputSystemで全てのアクションマップ、アクション、キーを取得する方法

全てのアクションマップの、全てのアクションに割り当てられたキーを全て取得するには、このように書きます。

InputActionMap actionMap;
InputAction action;
InputBinding bind;
string actionMapName;
string actionName;

for (int am = 0; am < playerInput.actions.actionMaps.Count; ++am) //全てのアクションマップを検索
{
    actionMap = playerInput.actions.actionMaps[am];
    actionMapName = actionMap.name;

    for (int a = 0; a < playerInput.actions.actionMaps[am].actions.Count; ++a)
    {
        action = playerInput.actions.actionMaps[am].actions[a];
        actionName = action.name;

        for(int b = 0; b < playerInput.actions.actionMaps[am].actions[a].bindings.Count; ++b)
        {
            bind = playerInput.actions.actionMaps[am].actions[a].bindings[b];

            Debug.Log("ActionMapName = " + actionMapName + " / ActionName = " + actionName + " / Bind = " + InputControlPath.ToHumanReadableString(bind.effectivePath));
        }
    }
}

すると、

このように取得することが可能です。

これで取得したキーの名前を画像に割り当てれば、ゲーム内で使用するキーを画像で表示させることができそうですね。(こんなの→

 

AssetsInput SystemUNITY
スポンサーリンク
Share
Follow Us
KITTYPOOL