I’ve been working on a controller system with the following goals in mind:
- Multiplayer
- Compatible with any type of input (touch, mouse clicks, joystick movement, etc.).
- Flexible
It’s quite difficult and want to know how everyone has designed their controller system. Here are some conclusions I’ve come up with / things I’ve done:
-
Virtual keys. Basically, all ‘real’ input (mouse clicks, taps, touches, joystick movement, etc.) are mapped to a virtual key. Everything interfaces through virtual keys. Virtual keys receive real input and do an action (move a character, jump, etc.) in response.
-
UnityEvents / Reflection will need to be used. Interfaces are not very flexible here. This is the part I’m having difficulties with. I think each key would carry one of 3 pieces of information: null, position (vector), and float. (Could a key possess a float and a vector?). In any case, the action(s) performed by the key should not be forced to implement a method with specific parameters. i.e. a mouse click will always have a position, but maybe the position aspect of it is not cared about. Another difficulty is what about key press duration? Let’s say you have a method like this:
Move(Vector2 position, float speed).
And you want it to be invoked when the user releases a key? the “speed” would be the duration the key was pressed for but what about “position”?
Any thoughts? Advise?