Game Development Reference
In-Depth Information
Once the two minor classes, Poster and Listener , are configured in the project, the
NotificationsManager can be used as intended. Simply play the scene and press any key on the
keyboard. When this happens, the Poster object notifies the NotificationsManager, which in turns
notifies the one and only listener for this event (see Figure 3-13 ). You could, of course, add more
listener instances to the scene, and the NotificationsManager would update those objects, too! Sure,
it's a simple setup in this isolated case, but it represents a powerful mechanic that works for any
event we can imagine, and it'll become indispensable to us as we progress further with CMOD.
Figure 3-13. The NotificationsManager at work, using the Listener and Poster sample classes
Conclusion
In this chapter, we established an abstract but highly important starting point for CMOD in the form
of a NotificationsManager class. This class is general in the ultimate sense that it stands apart from
any particular game project, and has wider relevance to practically every game project imaginable,
including CMOD. Its purpose is to centrally receive a single notification from any object in a
Unity scene that detects and causes events. And then, having received that notification, it should
immediately go on to dispatch it to any and all objects that have registered an interest in the event—
these objects being referred to as Listeners. Don't be fooled by the simplicity and “shortness” of this
class. As we'll see, it is powerful! At this point, you should be able to do the following:
Create C# script files and define custom behavior
Understand the problems of events and event handling, as well as the need for
streamlining and managing events
Understand how the NotificationsManager works, and its relationship to
Notifications and Listeners
 
Search WWH ::




Custom Search