Hey everyone,
We’ve set up a custom HID layout (flightstick) and it works in the editor. However, there is no response when we test with a build, though other automatically generated input (keyboard/xbox controller) do work.
The code is taken from the documentation and filled out to match the device information:
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Layouts;
[InputControlLayout(stateType = typeof(ThrustmasterHIDInputReport))]
#if UNITY_EDITOR
[InitializeOnLoad]
#endif
public class ThrustmasterJoystrickHID : Joystick
{
static ThrustmasterJoystrickHID()
{
InputSystem.RegisterLayout<ThrustmasterJoystrickHID>(
matches: new InputDeviceMatcher()
.WithInterface("HID")
.WithCapability("vendorId", 1973)
.WithCapability("productId", 790));
}
[RuntimeInitializeOnLoadMethod]
static void Init() { }
}
using System.Runtime.InteropServices;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;
[StructLayout(LayoutKind.Explicit, Size = 32)]
struct ThrustmasterHIDInputReport : IInputStateTypeInfo
{
public FourCC format => new FourCC('H', 'I', 'D');
[FieldOffset(0)] public byte reportId;
[InputControl(name = "stick", layout = "Stick", format = "VEC2")]
[InputControl(name = "stick/x", offset = 0, format = "BYTE",
parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,invert")]
[InputControl(name = "stick/y", offset = 1, format = "BYTE",
parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
[FieldOffset(1)] public byte stickX;
[FieldOffset(2)] public byte stickY;
[InputControl(name = "trigger", layout = "Button", offset = 5, bit = 4)]
[FieldOffset(3)] public byte trigger;
}