In Unity3D how do I manage input among many components, especially in relation to "blocking" input messages to certain components?
To make my question clear, an example:
Component 1: Input Manager
Manages a list of components that require input. They do this via a Register method, which adds the component to a List. Each registered component can poll input via this method:
public static bool GetKeyUpAndActive(KeyCode keyCode, MonoBehaviour entity) { return Input.GetKeyUp(keyCode) && List.Contains(entity); } This feels clunky, as each entity needs to pass itself to the manager, and the manager has to keep a list of registered input events.
Component 2: Script Manager
Manages scripts such as "Open Dialogue Box, say "Hello", play SFX, add Item x to inventory. Script manager responds to input, for example, if over component, and Input.Action is pressed, run this script.
Component 3: Dialogue Manager
Manages the dialogue box, pretty stock standard stuff. It also responds to input, pressing Input.Action will cycle through the dialogue boxes, until it reaches the end, then returns back to the game.
The main issue I am facing is that the script manager and the dialogue manager are responding to the Input.Action during their own updates. So Script 001 responds to Input.Action which triggers an open dialogue box, but because dialogue manager also responds, it has already cycled through to the next dialogue box.
I think the Input Manager is breaking encapsulation. I also feel like I'm missing an obvious component here, maybe I need a stronger subscriber pattern to follow, or should there be a separate state manager, and if so, should the input manager only send events/provide methods to components in the correct state, or should components check the state machine themselves?
Updatemethods and the like of their own). \$\endgroup\$