These are the result of me trying to follow the wondrous journey of confusion that is the input system guide pages and adapt the ps4 controller example.
I remapped the controller to be two half-controllers but i mapped SL and SR to L3 and R3 and did not map the stick press itself. Also the Stick is read as a dpad for some reason, so not analog.
There is a lot you can improve on this, i would call this a work in progress but it works for me.
using System.Runtime.InteropServices;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;
[StructLayout(LayoutKind.Explicit, Size = 32)]
struct LeftJoyconInputReport : IInputStateTypeInfo
{
// Because all HID input reports are tagged with the 'HID ' FourCC,
// this is the format we need to use for this state struct.
public FourCC format => new FourCC('H', 'I', 'D');
[InputControl(name = "buttonSouth", displayName = "Down", bit = 1)]
[InputControl(name = "buttonWest", displayName = "Left", bit = 0)]
[InputControl(name = "buttonEast", displayName = "Right", bit = 3)]
[InputControl(name = "buttonNorth", displayName = "Up", bit = 2)]
[InputControl(name = "leftStickPress", displayName = "SL", bit = 4)]
[InputControl(name = "rightStickPress", displayName = "SR", bit = 5)]
[FieldOffset(1)] public byte buttons1;
//Stickpress is not assigned
// [InputControl(name = "leftStickPress", displayName = "StickPress", bit = 2)]
[InputControl(name = "start", displayName = "Minus", bit = 0)]
[InputControl(name = "select", displayName = "Cam", bit = 5)]
[InputControl(name = "leftTrigger", displayName = "Trigger", format = "BIT", bit = 7)]
[InputControl(name = "leftShoulder", displayName = "Shoulder", bit = 6)]
[FieldOffset(2)] public byte buttons2;
[InputControl(name = "dpad", format = "BIT", layout = "Dpad", sizeInBits = 4, defaultState = 8)]
[InputControl(name = "dpad/up", format = "BIT", layout = "DiscreteButton", parameters = "minValue=5,maxValue=7", bit = 0, sizeInBits = 4)]
[InputControl(name = "dpad/right", format = "BIT", layout = "DiscreteButton", parameters = "minValue=7,maxValue=1,nullValue=8,wrapAtValue=7", bit = 0, sizeInBits = 4)]
[InputControl(name = "dpad/down", format = "BIT", layout = "DiscreteButton", parameters = "minValue=1,maxValue=3", bit = 0, sizeInBits = 4)]
[InputControl(name = "dpad/left", format = "BIT", layout = "DiscreteButton", parameters = "minValue=3, maxValue=5", bit = 0, sizeInBits = 4)]
[FieldOffset(3)] public byte leftStickX;
}
[StructLayout(LayoutKind.Explicit, Size = 32)]
struct RightJoyconInputReport : IInputStateTypeInfo
{
// Because all HID input reports are tagged with the 'HID ' FourCC,
// this is the format we need to use for this state struct.
public FourCC format => new FourCC('H', 'I', 'D');
[InputControl(name = "buttonSouth", displayName = "Down", bit = 2)]
[InputControl(name = "buttonWest", displayName = "Left", bit = 3)]
[InputControl(name = "buttonEast", displayName = "Right", bit = 0)]
[InputControl(name = "buttonNorth", displayName = "Up", bit = 1)]
[InputControl(name = "leftStickPress", displayName = "SL", bit = 4)]
[InputControl(name = "rightStickPress", displayName = "SR", bit = 5)]
[FieldOffset(1)] public byte buttons1;
//Stickpress is not assigned
// [InputControl(name = "rightStickPress", displayName = "StickPress", bit = 3)]
[InputControl(name = "start", displayName = "Plus", bit = 1)]
[InputControl(name = "select", displayName = "Home", bit = 4)]
[InputControl(name = "rightTrigger", displayName = "Trigger", bit = 7, format = "BIT")]
[InputControl(name = "rightShoulder", displayName = "Shoulder", bit = 6)]
[FieldOffset(2)] public byte buttons2;
[InputControl(name = "dpad", format = "BIT", layout = "Dpad", sizeInBits = 4, defaultState = 8)]
[InputControl(name = "dpad/up", format = "BIT", layout = "DiscreteButton", parameters = "minValue=1,maxValue=3", bit = 0, sizeInBits = 4)]
[InputControl(name = "dpad/right", format = "BIT", layout = "DiscreteButton", parameters = "minValue=3,maxValue=5", bit = 0, sizeInBits = 4)]
[InputControl(name = "dpad/down", format = "BIT", layout = "DiscreteButton", parameters = "minValue=5, maxValue=7", bit = 0, sizeInBits = 4)]
[InputControl(name = "dpad/left", format = "BIT", layout = "DiscreteButton", parameters = "minValue=7,maxValue=1,nullValue=8,wrapAtValue=7", bit = 0, sizeInBits = 4)]
[FieldOffset(3)] public byte rightStickX;
}
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Layouts;
[InputControlLayout(stateType = typeof(LeftJoyconInputReport))]
#if UNITY_EDITOR
[InitializeOnLoad] // Make sure static constructor is called during startup.
#endif
public class LeftJoyconGamepadHID : Gamepad
{
static LeftJoyconGamepadHID()
{
InputSystem.RegisterLayout<LeftJoyconGamepadHID>(
matches: new InputDeviceMatcher()
.WithInterface("HID")
.WithCapability("vendorId", 0x57E) // Nintendo
.WithCapability("productId", 0x2006)); // L
}
// In the Player, to trigger the calling of the static constructor,
// create an empty method annotated with RuntimeInitializeOnLoadMethod.
[RuntimeInitializeOnLoadMethod]
static void Init() {}
}
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Layouts;
[InputControlLayout(stateType = typeof(RightJoyconInputReport))]
#if UNITY_EDITOR
[InitializeOnLoad] // Make sure static constructor is called during startup.
#endif
public class RightJoyconGamepadHID : Gamepad
{
static RightJoyconGamepadHID()
{
InputSystem.RegisterLayout<RightJoyconGamepadHID>(
matches: new InputDeviceMatcher()
.WithInterface("HID")
.WithCapability("vendorId", 0x57E)//Nintendo
.WithCapability("productId", 0x2007)); //R
}
// In the Player, to trigger the calling of the static constructor,
// create an empty method annotated with RuntimeInitializeOnLoadMethod.
[RuntimeInitializeOnLoadMethod]
static void Init() {}
}