Developer Console

Amazon Input SDK for Unity Input System

Unity provides the Input System package, which you can use to map device input controls to actions in your app. The Amazon Input SDK for Unity Input System is an additional plugin that works with the Unity Input System. It uses the Action Map that you define in the Unity Input System to show users help dialogs, which describe how to use your app with a keyboard and mouse.

Get started

Follow these steps to set up the Amazon Input SDK for Unity Input System.

  1. Add the Amazon Input SDK for Unity to your project. For details, follow the instructions in Add the Input SDK to your project.
  2. If you haven't done so already, set up the Unity Input System in your project. For instructions, see Unity's Installation Guide for the Input System.

  3. In your app, create an Action Map. For instructions, see Unity's Action article for the Input System.

  4. Import the Amazon Input SDK for Unity Input System plugin into your project.
    1. From the Assets menu, select Import Package > Custom Package.
    2. Browse for and select Amazon.Device.InputMapping.InputSystemCompatibility-1.0.0.unitypackage.
    3. Select all the files in the subsequent import dialog and click Import.

To use the Amazon Input SDK for Unity Input System, first register the input mapping provider in your app, then you can display the help screen.

Register an input mapping provider

There can only be one active input map at a time. When a user accesses the help screen, they are shown the currently active input map. Register an input mapping provider as the active input mapping provider through the Input static class as shown in the following example.

void Start()
{
    var _inputMappingClient = Input.GetInputMappingClient();
    _inputMappingClient.SetInputMappingProvider(
        new UnityInputSystemMappingProvider(playerInput.currentActionMap)
    );
}

Display the help screen

To display the help screen, the Appstore recommends displaying a visual element to the user that, when clicked, opens the help screen. You can place the visual indicator either within the game window, or in a separate screen, such as a preferences or controls page. Display the help screen using the TriggerHandler.ShowHelp() method as shown.

TriggerHandler.ShowHelp("Title of the app");

Sample usage

The following code shows an example of how to use the Amazon Input SDK for Unity using Unity's Input System.

using UnityEngine;
using UnityEngine.InputSystem;
using UnityInput = UnityEngine.Input;
using Amazon.Device.InputMapping;

public class Football : MonoBehaviour
{
    public Rigidbody2D myRidigBody;
    private PlayerInput playerInput;

    void Start()
    {
        InitializeInput();
    }

    // Update is called once per frame
    void Update()
    {
        if (UnityInput.GetKeyDown(KeyCode.Space))
        {
            myRidigBody.velocity = Vector2.up * 10;
        }
        if (UnityInput.GetKeyDown(KeyCode.Tab))
        {
            myRidigBody.velocity = Vector2.up * 10;
        }
        if (UnityInput.GetKeyDown(KeyCode.Return))
        {
            Debug.Log("Showing help...");
            TriggerHandler.ShowHelp("My App");
        }

    }
    void InitializeInput()
    {
        var imc = Amazon.Device.InputMapping.Input.GetInputMappingClient();

        // If Action Map created through code

        var map = new InputActionMap("Gameplay");
        var lookAction = map.AddAction("look");
        lookAction.AddBinding("<Gamepad>/leftStick");
        imc.SetInputMappingProvider(new UnityInputSystemMappingProvider(map));


        // If Action Map created through InputSystem UI

        //If C# Class generated for InputActions
        // Method 1
        InputActionAsset asset = new @Custominputs().asset;
        imc.SetInputMappingProvider(new UnityInputSystemMappingProvider(
            asset.actionMaps[0]
        ));
        //Method 2
        InputActionMap actionMap = new @Custominputs().Player;
        imc.SetInputMappingProvider(new UnityInputSystemMappingProvider(
            actionMap
        ));


        //If C# Class not generated
        //Method 1 Recommended: Since automatically select current ActionMap 
        // selected in PlayerInput Component
        playerInput = GetComponent<PlayerInput>();
        imc.SetInputMappingProvider(new UnityInputSystemMappingProvider(
            playerInput.currentActionMap
        ));
    }
}

Last updated: Mar 05, 2024