Game Development Reference
In-Depth Information
// Clear subscribers method for manager
public void ClearAllUIEventSubscribers()
{
uiEventSubscribers.Clear();
}
Note
You will note we only use a copy of the subscribers array. This is to ensure that the loop
does not fall over when new subscriptions are added or existing ones are removed while it
is progressing through the loop. It is unlikely in this scenario; however, it is a good prac-
tice to follow either this option or use locking methods to ensure that the array cannot be
updated when the listis being traversed.
This ensures that when GUI events happen (if the game is paused and a pause menu is dis-
played or, as in this case, when the travel prompt appears), the GUI system just has one
place to tell all scenes and objects that are listening through messaging when the GUI is in
focus in the game (everyone else stop talking, GUI has the floor), and when it's finished
So, next we need to update our NavigationPrompt script to broadcast when the GUI
is displayed and when it is hidden. First, let's refactor a bit and add a new method that
controls what happens when the dialog state needs to change:
void DialogVisible(bool visibility)
{
showDialog = visibility;
MessagingManager.Instance.BroadcastUIEvent(visibility);
}
This just sets the showDialog flag we were using to the new state and then follows up
by sending a broadcast of the new state ( true means visible and false means not invis-
ible). Next, wherever we were previously changed the showDialog flag, we need to up-
date it to use the new helper function. So, change the showDialog flag to the following:
showDialog = false -> DialogVisible(false);
showDialog = true -> DialogVisible(true);
Search WWH ::




Custom Search