- Home /
Default Event Handler
Talking about Unity.EventSystems, what is the best way to handle events that were not consumed eg. by the selected object, or anything else (if selected object ignores the event or if nothing is selected)? Basically, I want to have normal keyboard input for the game, but I want the GUI to have priority - when i am typing, keyboard won't move the character. Should i NOT use UnityEngine.Input, but rather some event handler similar to UI elements? Like IUpdateSelectedHandler? How do i make sure my controller receives all unhandled events?
Answer by coolraiman · May 10, 2016 at 01:40 PM
a simple boolean can do the dirty trick
wen you gui show up, set the boolean to false and where you manage your keyboard input, check if the boolean is true or false
Well not exactly... my UI can be visible all the time, but let's say there's a focus on InputField which consumes the key event when it's selected. If it doesn't, the event should be passed to some default handler
Also i am trying to come up with a framework solution. EventSystem is a framework for handing events and it's a dependency of all UI code. Now I don't want to add extra dependencies to some custom "boolean holder" to every UI and every input user (both can come eg. from a plugin), that's EventSystem's job. Object that's selected receives an event. These events have Used state, similar to immediate gui events. So i believe unused events are forwarded to the next possible handler.