Is it possible to create a binding similar to the 1D axis and 2D vector composites, but where each binding is mapped to a specific integer?
My use case is an inventory system, where keyboard keys 1, 2, 3, 4, and TAB each select a different inventory group.
Preferred mapping would then be:
1 = 0,
2 = 1,
3 = 2,
4 = 3,
TAB = 4
Edit: By mapping I mean number returned by ReadValue
The answer was to create a custom composite. Albeit clunky it works
using UnityEngine.InputSystem.Utilities;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem;
using UnityEngine;
using UnityEditor;
#if UNITY_EDITOR
[InitializeOnLoad] // Automatically register in editor.
#endif
[DisplayStringFormat("{firstPart}+{secondPart}")]
public class IndexedComposite : InputBindingComposite<int>
{
[InputControl(layout = "Button")] public int id_1;
[InputControl(layout = "Button")] public int id_2;
[InputControl(layout = "Button")] public int id_3;
[InputControl(layout = "Button")] public int id_4;
[InputControl(layout = "Button")] public int id_5;
public override int ReadValue(ref InputBindingCompositeContext context)
{
var a = context.ReadValueAsButton(id_1);
var b = context.ReadValueAsButton(id_2);
var c = context.ReadValueAsButton(id_3);
var d = context.ReadValueAsButton(id_4);
var e = context.ReadValueAsButton(id_5);
if (a) return 1;
if (b) return 2;
if (c) return 3;
if (d) return 4;
if (e) return 5;
return 0;
}
static IndexedComposite()
{
InputSystem.RegisterBindingComposite<IndexedComposite>();
}
[RuntimeInitializeOnLoadMethod]
static void Init() { } // Trigger static constructor.
}