Game Development Reference
In-Depth Information
084 {
085 if(!ListenList[i].Equals(null))
086 ListenList[i].OnEvent(Event_Type, Sender, Param);
087 }
088 }
089 //-----------------------------------------------------------
090 //Remove event from dictionary, including all listeners
091 public void RemoveEvent(EVENT_TYPE Event_Type)
092 {
093 //Remove entry from dictionary
094 Listeners.Remove(Event_Type);
095 }
096 //-----------------------------------------------------------
097 //Remove all redundant entries from the Dictionary
098 public void RemoveRedundancies()
099 {
100 //Create new dictionary
101 Dictionary<EVENT_TYPE, List<IListener>>
TmpListeners = new Dictionary<EVENT_TYPE, List<IListener>>();
102
103 //Cycle through all dictionary entries
104 foreach(KeyValuePair<EVENT_TYPE, List<IListener>>
Item in Listeners)
105 {
106 //Cycle all listeners, remove null objects
107 for(int i = Item.Value.Count-1; i>=0; i--)
108 {
109 //If null, then remove item
110 if(Item.Value[i].Equals(null))
111 Item.Value.RemoveAt(i);
112 }
113
114 //If items remain in list, then add to tmp dictionary
115 if(Item.Value.Count > 0)
116 TmpListeners.Add (Item.Key, Item.Value);
117 }
118
119 //Replace listeners object with new dictionary
120 Listeners = TmpListeners;
 
Search WWH ::




Custom Search