I use a string Array for the InputAction Name.
string[] gameplayNames = new string[]
{
"Fire",
"Utility",
"Special",
"Drone",
"Vertical",
"Torque",
"HELLO"
};
Another jagged Array for the bindings
string[][] p1KeyboardGameplayBindings = new string[][]
{
new string[]{"<Keyboard>/T"},
new string[]{"<Keyboard>/Y"},
new string[]{"<Keyboard>/U"},
new string[]{"<Keyboard>/G"},
new string[]{"<Keyboard>/W","<Keyboard>/S"},
new string[]{"<Keyboard>/A","<Keyboard>/D"},
new string[]{"<Keyboard>/K","<Keyboard>/L"},
};
then I use this method to add InputActions to the map.
void SetPlayerActionMap(InputActionMap map, string[] names, string[][] bindings)
{
int i= 0;
InputAction tempAction;
while (i<names.Length)
{
if (bindings*.Length == 1)*
{
map.AddAction(names_, binding: bindings*[0]);_
_print(map.FindAction(names));
}
else
{_
_tempAction = map.AddAction(names);
tempAction.AddCompositeBinding(“Axis(minValue=-1,maxValue=1)”)
``.With(“Positive”, bindings[0])
.With(“Negative”, bindings[1]);
}
i++;
}
map.Enable();
}*
In the player script I subscribed this method to All InputActionsWith Composite bindings._
verticalAction = playerMap.FindAction(“Vertical”);
horizontalAction = playerMap.FindAction(“Torque”);
pepega = playerMap.FindAction(“HELLO”);
verticalAction.started += context => OnVertical(context);
verticalAction.canceled += context => OnVertical(context);
horizontalAction.started += context => OnVertical(context);
horizontalAction.canceled += context => OnVertical(context);
pepega.started += context => OnVertical(context);
pepega.canceled += context => OnVertical(context);
public void OnVertical(InputAction.CallbackContext context)
{
print(Mathf.RoundToInt(context.ReadValue()));
}
the Last InputAction with compostite bindings that was added to the map always returns positive value regardles of button press.