Game Development Reference
In-Depth Information
090 if(!Listeners.TryGetValue(Event_Type, out ListenList))
091 return;
092
093 //Entry exists. Now notify appropriate listeners
094 for(int i=0; i<ListenList.Count; i++)
095 {
096 if(!ListenList[i].Equals(null))
097 ListenList[i](Event_Type, Sender, Param);
098 }
099 }
100 //-----------------------------------------------------------
101 //Remove event from dictionary, including all listeners
102 public void RemoveEvent(EVENT_TYPE Event_Type)
103 {
104 //Remove entry from dictionary
105 Listeners.Remove(Event_Type);
106 }
107 //-----------------------------------------------------------
108 //Remove all redundant entries from the Dictionary
109 public void RemoveRedundancies()
110 {
111 //Create new dictionary
112 Dictionary<EVENT_TYPE, List<OnEvent>> TmpListeners
= new Dictionary<EVENT_TYPE, List< OnEvent >>();
113
114 //Cycle through all dictionary entries
115 foreach(KeyValuePair<EVENT_TYPE, List< OnEvent >>
Item in Listeners)
116 {
117 //Cycle through all listeners
118 for(int i = Item.Value.Count-1; i>=0; i--)
119 {
120 //If null, then remove item
121 if(Item.Value[i].Equals(null))
122 Item.Value.RemoveAt(i);
123 }
124
125 //If items remain, then add to tmp dictionary
126 if(Item.Value.Count > 0)
127 TmpListeners.Add (Item.Key, Item.Value);
 
Search WWH ::




Custom Search