Game Development Reference
In-Depth Information
046 public void AddListener(EVENT_TYPE Event_Type, IListener
Listener)
047 {
048 //List of listeners for this event
049 List<IListener> ListenList = null;
050
051 // Check existing event type key. If exists, add to
list
052 if(Listeners.TryGetValue(Event_Type, out ListenList))
053 {
054 //List exists, so add new item
055 ListenList.Add(Listener);
056 return;
057 }
058
059 //Otherwise create new list as dictionary key
060 ListenList = new List<IListener>();
061 ListenList.Add(Listener);
062 Listeners.Add(Event_Type, ListenList);
063 }
064 //-----------------------------------------------------------
065 /// <summary>
066 /// Function to post event to listeners
067 /// </summary>
068 /// <param name="Event_Type">Event to invoke</param>
069 /// <param name="Sender">Object invoking event</param>
070 /// <param name="Param">Optional argument</param>
071 public void PostNotification(EVENT_TYPE Event_Type,
Component Sender, Object Param = null)
072 {
073 //Notify all listeners of an event
074
075 //List of listeners for this event only
076 List<IListener> ListenList = null;
077
078 //If no event exists, then exit
079 if(!Listeners.TryGetValue(Event_Type, out ListenList))
080 return;
081
082 //Entry exists. Now notify appropriate listeners
083 for(int i=0; i<ListenList.Count; i++)
 
Search WWH ::




Custom Search