Beispiel #1
0
    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);
        }
    }
Beispiel #2
0
 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);
 }
Beispiel #3
0
 public static void DelGameEventCallBack(gGameEventType evtType, GameEventCallBack handler)
 {
     if (gameEvtCallbackMap.ContainsKey(evtType))
     {
         gameEvtCallbackMap[evtType] -= handler;
         if (gameEvtCallbackMap [evtType] == null)
         {
             gameEvtCallbackMap.Remove(evtType);
         }
     }
 }
Beispiel #4
0
 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);
    }
Beispiel #7
0
    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);
 }
Beispiel #9
0
 public void Reset()
 {
     hashcode = 0;
     callback = null;
 }
Beispiel #10
0
 public void Set(int hc, GameEventCallBack cb)
 {
     hashcode = hc;
     callback = cb;
 }
Beispiel #11
0
 public void AddEventListener(string evt, GameEventCallBack callback)
 {
     AddEventListener(evt, callback, null);
 }