Game Development Reference
In-Depth Information
Note
It may be advantageous to have both the GUI and game input working at the same time,
for example, in situations where you have in-game buttons for actions. In these cases, you
would test where on the screen the player interacted to decide which area gets the input.
However, when the pause menu or alternate screen appears, you are still going to need to
handle input priority.
So in the MessagingManager script, we add the following new handler to manage the
GUI events. We also need to track whether the GUI is displayed or not, so we also need to
manage a parameter for the event using a Boolean ( true means GUI is displayed and
false means GUI is hidden):
private List<Action<bool>> uiEventSubscribers = new
List<Action<bool>>();
Then, like before, we need a subscribing and broadcasting function for the new event:
// Subscribe method for UI manager
public void SubscribeUIEvent(Action<bool> subscriber)
{
uiEventSubscribers.Add(subscriber);
}
// Broadcast method for UI manager
public void BroadcastUIEvent(bool uIVisible)
{
foreach (var subscriber in uiEventSubscribers.ToArray())
{
subscriber(uIVisible);
}
}
// Unsubscribe method for UI manager
public void UnSubscribeUIEvent(Action<bool> subscriber)
{
uiEventSubscribers.Remove(subscriber);
}
Search WWH ::




Custom Search