private void removeObserver(List <MGNotificationSelector> selList, string name) { if (selList == null) { return; } List <MGNotificationSelector> notiSelList, needDelList; needDelList = new List <MGNotificationSelector>(); notiSelList = MGFoundtion.GetValue <string, List <MGNotificationSelector> >(this.nameHastable, name, null); if (notiSelList == null) { return; } //Debug.Log("before remove:"+selList.Count); foreach (MGNotificationSelector eachSel in notiSelList) { foreach (MGNotificationSelector delSel in selList) { if (delSel == eachSel) { needDelList.Add(delSel); } } } foreach (MGNotificationSelector needDelSel in needDelList) { notiSelList.Remove(needDelSel); } // Debug.Log("after remove:"+selList.Count); needDelList.Clear(); }
/// <summary> /// Removes the observer. /// </summary> /// <param name="observer">Observer.</param> /// <param name="name">Name.</param> public void removeObserver(object observer, string name) { Dictionary <string, List <MGNotificationSelector> > nameListDic = MGFoundtion.GetValue <object, Dictionary <string, List <MGNotificationSelector> > >(this.objcNamesSel, observer, null); if (nameListDic == null) { return; } // Debug.Log("123123"); this.removeObserver(nameListDic[name], name); nameListDic.Remove(name); }
/// <summary> /// Removes the observer. /// </summary> /// <param name="observer">Observer.</param> public void removeObserver(object observer) { Dictionary <string, List <MGNotificationSelector> > nameListDic = MGFoundtion.GetValue <object, Dictionary <string, List <MGNotificationSelector> > >(this.objcNamesSel, observer, null); if (nameListDic == null) { return; } foreach (KeyValuePair <string, List <MGNotificationSelector> > pair in nameListDic) { this.removeObserver(pair.Value, pair.Key); } }
/// <summary> /// Posts the notification. /// </summary> /// <param name="name">Name.</param> /// <param name="objc">Objc.</param> /// <param name="userInfo">User info.</param> public void postNotification(string name, object objc, Dictionary <object, object> userInfo) { List <MGNotificationSelector> selList = MGFoundtion.GetValue <string, List <MGNotificationSelector> >(this.nameHastable, name, null); if (selList == null) { return; } foreach (MGNotificationSelector sel in selList) { sel(new MGNotification(name, objc, userInfo)); } }
/// <summary> /// Adds the observer. /// </summary> /// <param name="observer">Observer.</param> /// <param name="sel">selector.</param> /// <param name="name">nitification Name.</param> public void addObserver(object observer, MGNotificationSelector sel, string name) { if (observer == null || sel == null || name == null) { return; } List <MGNotificationSelector> selList = MGFoundtion.GetValue <string, List <MGNotificationSelector> >(this.nameHastable, name, null); if (selList == null) { selList = new List <MGNotificationSelector>(); } if (selList.Contains(sel)) { return; } selList.Add(sel); //Debug.Log("after add sel:"+selList.Count); MGFoundtion.AddOrPeplace <string, List <MGNotificationSelector> >(this.nameHastable, name, selList); Dictionary <string, List <MGNotificationSelector> > nameListDic = MGFoundtion.GetValue <object, Dictionary <string, List <MGNotificationSelector> > >(this.objcNamesSel, observer, null); if (nameListDic == null) { nameListDic = new Dictionary <string, List <MGNotificationSelector> >(); } List <MGNotificationSelector> obj_name_selList = MGFoundtion.GetValue <string, List <MGNotificationSelector> >(nameListDic, name, null); if (obj_name_selList == null) { obj_name_selList = new List <MGNotificationSelector>(); } obj_name_selList.Add(sel); MGFoundtion.AddOrPeplace <string, List <MGNotificationSelector> >(nameListDic, name, obj_name_selList); MGFoundtion.AddOrPeplace <object, Dictionary <string, List <MGNotificationSelector> > >(this.objcNamesSel, observer, nameListDic); //Debug.Log("objcNamesSel count:" + this.objcNamesSel.Count); }