After jumping through a lot of hoops, I finally managed to write the code for control bindings… but almost…
From player’s point of view, it is standard binding procedure. Inside the options menu/controls panel, there is a button named “jump” and when player clicks on it, game is going to wait for input of a new key. And this works… but only for keyboard keys and mouse buttons. Unless I write a really bizarre piece of code, I am unable to find solution for joystick/pad buttons to be accepted as well.
I am using OnGUI for this:
void OnGUI
{
[...]
event e = e.current;
if(e.isKey || e.isMouse)
{
[...]
if(e.isKey)
{
if(e.keyCode != KeyCode.Escape)
ControlBinds.buttonJump = e.keyCode;
else
ControlBinds.buttonJump = KeyCode.None;
}
else if(e.isMouse)
{
if(e.button == 0)
ControlBinds.buttonJump = KeyCode.Mouse0;
else if(e.button == 1)
ControlBinds.buttonJump = KeyCode.Mouse1;
else if(e.button == 2)
ControlBinds.buttonJump = KeyCode.Mouse2;
}
[...]
}
[...]
}
Btw, second if
and following else if
are yet another ugly piece of code, but it was the only way for me to force mouse button bindings to be accepted. And that only for three standard mouse buttons. Whatever KeyCode.Mouse3/4/5/6/7/8 are, those do not recognize my mouse’s 4,5,6,7 buttons. Anyway, I am really missing here something like… e.isJoy
( if(e.isKey || e.isMouse || e.isJoy)
) and e.joyButton
( else if(e.joyButton)
), which is what is preventing me for allowing joystick button binds. It’s quite frustrating that e.keyCode
sees only keyboard keys, while KeyCode
enum has mouse and joystick stuff as well. Is there a sane way around this limitation, perhaps?