I am writing a custom device to add support for my DualShock 3 controller on Windows. I’ve managed to figure out most of it, apart from the two triggers.
[InputControl(name = "leftTrigger", format = "BYTE")]
[FieldOffset(11)] public byte leftTrigger;
[InputControl(name = "rightTrigger", format = "BYTE")]
[FieldOffset(12)] public byte rightTrigger;
These are the right offsets but, in the Input Debugger, they start with a value of 1 and change to 0 when fully pressed. How do I change these to start at 0 and move to 1 when fully pressed?
I’ve looked at Processors but, apart from writing my own, the closest I can get is Invert
which starts at -1 and changes to 0 when fully pressed.
Thanks!
My friend suggested, at least temporarily, to use a custom processor that flips the value based on a defined maxValue.
I imagined there might be a built-in solution I was missing but, for now, this works:
#if UNITY_EDITOR
[InitializeOnLoad]
#endif
public class FlipProcessor : InputProcessor<float>
{
#if UNITY_EDITOR
static FlipProcessor()
{
Initialize();
}
#endif
[RuntimeInitializeOnLoadMethod]
static void Initialize()
{
InputSystem.RegisterProcessor<FlipProcessor>();
}
[Tooltip("TODO - Tooltip required")]
public float maxValue = 1;
public override float Process(float value, InputControl control)
{
return this.maxValue - value;
}
}
[InputControl(name = "leftTrigger", format = "BYTE", processors = "flip(maxValue=1)")]
[FieldOffset(11)] public byte leftTrigger;
[InputControl(name = "rightTrigger", format = "BYTE", processors = "flip(maxValue=1)")]
[FieldOffset(12)] public byte rightTrigger;