Skip to content

Latest commit

 

History

History
48 lines (39 loc) · 1.2 KB

File metadata and controls

48 lines (39 loc) · 1.2 KB
uid input-system-use-existing-layout

Use an existing input device to create a layout

To use one of the existing C# InputDevice classes in code to interface with a device, you can build on an existing layout using JSON:

   {
        "name" : "MyDevice",
        "extend" : "Gamepad", // Or some other thing
        "controls" : [
            {
                "name" : "firstButton",
                "layout" : "Button",
                "offset" : 0,
                "bit": 0,
                "format" : "BIT",
            },
            {
                "name" : "secondButton",
                "layout" : "Button",
                "offset" : 0,
                "bit": 1,
                "format" : "BIT",
            },
            {
                "name" : "axis",
                "layout" : "Axis",
                "offset" : 4,
                "format" : "FLT",
                "parameters" : "clamp=true,clampMin=0,clampMax=1"
            }
        ]
    }

You then register your layout with the system and then instantiate it:

   InputSystem.RegisterControlLayout(myDeviceJson);
    var device = InputSystem.AddDevice("MyDevice");