public void AddEventListener(string evt, GameEventCallBack callback, object owner) { List <EUnit> tList = null; if (!mGameEvent2Listeners.TryGetValue(evt, out tList)) { tList = BorrowList(); mGameEvent2Listeners.Add(evt, tList); } bool bHas = false; for (int i = 0; i < tList.Count; i++) { if (tList[i].callback == callback) { bHas = true; break; } } if (!bHas) { EUnit tEUnit = BorrowEUnit(); tEUnit.Set((owner == null ? 0 : owner.GetHashCode()), callback); tList.Add(tEUnit); } }
public virtual void AddListener(object o, GameEventCallBack e) { if (eventDictionary.ContainsKey(o)) { Debug.Log("this key is Exist:" + o.ToString()); return; } eventDictionary.Add(o, e); }
public static void DelGameEventCallBack(gGameEventType evtType, GameEventCallBack handler) { if (gameEvtCallbackMap.ContainsKey(evtType)) { gameEvtCallbackMap[evtType] -= handler; if (gameEvtCallbackMap [evtType] == null) { gameEvtCallbackMap.Remove(evtType); } } }
public static void AddGameEventCallBack(gGameEventType evtType, GameEventCallBack handler) { if (gameEvtCallbackMap.ContainsKey(evtType)) { gameEvtCallbackMap[evtType] += handler; } else { gameEvtCallbackMap.Add(evtType, handler); } }
void DeRegisterEventListener(SGameEventType pEventType, GameEventCallBack pCallBack) { int type = (int)pEventType; if (mListeners.ContainsKey(type)) { if (mListeners[type].Contains(pCallBack)) { mListeners[type].Remove(pCallBack); } } }
void RegisterEventListener(SGameEventType pEventType, GameEventCallBack pCallBack) { int type = (int)pEventType; if (!mListeners.ContainsKey(type)) { mListeners[type] = new List <GameEventCallBack>(); } else if (Application.isEditor) { // check if listener is already registered if (mListeners[type].Contains(pCallBack)) { Debug.LogError(System.String.Format("{0}, {1}, Event Listener is already registered!", pCallBack, pEventType)); } } mListeners[(int)pEventType].Add(pCallBack); }
public void RemoveEventListener(string evt, GameEventCallBack callback) { List <EUnit> tList = null; if (mGameEvent2Listeners.TryGetValue(evt, out tList)) { for (int i = 0; i < tList.Count; i++) { if (tList[i].callback == callback) { ReturnEUnit(tList[i]); tList.RemoveAt(i); break; } } if (tList.Count <= 0) { ReturnList(tList); mGameEvent2Listeners.Remove(evt); } } }
public static void RemoveEventListener(SGameEventType pEventType, GameEventCallBack pCallBack) { mInstance.DeRegisterEventListener(pEventType, pCallBack); }
public void Reset() { hashcode = 0; callback = null; }
public void Set(int hc, GameEventCallBack cb) { hashcode = hc; callback = cb; }
public void AddEventListener(string evt, GameEventCallBack callback) { AddEventListener(evt, callback, null); }