Game Development Reference
In-Depth Information
128 }
129
130 //Replace listeners with new dictionary
131 Listeners = TmpListeners;
132 }
133 //-----------------------------------------------------------
134 //Called on scene change. Clean up dictionary
135 void OnLevelWasLoaded()
136 {
137 RemoveRedundancies();
138 }
139 //-----------------------------------------------------------
140 #endregion
141 }
More information on C# delegates can be found in the Microsoft
documentation at http://msdn.microsoft.com/en-gb/
library/aa288459%28v=vs.71%29.aspx .
The following are the comments on the code sample 4-7:
Lines 005-011 : Here, the event type enumeration has been shifted into
the EventManager file from the original IListener class. Since the
delegate implementation avoids the need for interfaces and for IListener
specifically, the enumeration can be shifted to the manager source file.
Line 032 : The public member OnEvent is declared as a delegate type. Notice
that the declaration is hybrid insofar as it combines variable declaration
style with a function prototype. This specifies the function prototype that
may be assigned to the delegate variable; any function with that structure
can be assigned from any class or any script file. Thus, the OnEvent function
becomes a delegate type, and this is used in the next statement creating the
internal dictionary.
Line 035 : The private dictionary listeners is declared, and for each event type,
an array of delegates (instead of interfaces) is stored; each delegate refers to a
function that should be invoked when the event occurs.
 
Search WWH ::




Custom Search