Game Development Reference
In-Depth Information
053 /// Add listener-object to array of listeners
054 /// </summary>
055 /// <param name="Event_Type">Event to Listen for</param>
056 /// <param name="Listener">Object to listen for
event</param>
057 public void AddListener(EVENT_TYPE Event_Type, OnEvent
Listener)
058 {
059 //List of listeners for this event
060 List< OnEvent > ListenList = null;
061
062 // Check existing event. If one exists, add to list
063 if(Listeners.TryGetValue(Event_Type, out ListenList))
064 {
065 //List exists, so add new item
066 ListenList.Add(Listener);
067 return;
068 }
069
070 //Otherwise create new list as dictionary key
071 ListenList = new List<OnEvent>();
072 ListenList.Add(Listener);
073 Listeners.Add(Event_Type, ListenList);
074 }
075 //-----------------------------------------------------------
076 /// <summary>
077 /// Function to post event to listeners
078 /// </summary>
079 /// <param name="Event_Type">Event to invoke</param>
080 /// <param name="Sender">Object invoking event</param>
081 /// <param name="Param">Optional argument</param>
082 public void PostNotification(EVENT_TYPE Event_Type,
Component Sender, object Param = null)
083 {
084 //Notify all listeners of an event
085
086 //List of listeners for this event only
087 List< OnEvent > ListenList = null;
088
089 //If no entry exists, then exit
 
Search WWH ::




Custom Search