Beispiel #1
0
    public static void Dispatch <T, U>(EventID eventId, T obj1, U obj2)
    {
        BaseEvents baseEvents;

        if (Instance.eventDictionary.TryGetValue(eventId, out baseEvents))
        {
            baseEvents.isLock = true;
            GenericEvents2 <T, U> impEvents = baseEvents as GenericEvents2 <T, U>;
            int count = impEvents.eventList.Count;
            for (int i = 0; i < count; ++i)
            {
                EventFun2 <T, U> dlgt = impEvents.eventList[i];
                dlgt(obj1, obj2);
            }
            if (impEvents.deleteRequests.Count > 0)
            {
                for (int i = 0; i < impEvents.deleteRequests.Count; ++i)
                {
                    impEvents.eventList.Remove(impEvents.deleteRequests[i]);
                }
                impEvents.deleteRequests.Clear();
            }
            baseEvents.isLock = false;
        }
    }
Beispiel #2
0
    public static void AddListener <T, U>(EventID eventId, EventFun2 <T, U> listener)
    {
        BaseEvents baseEvents = null;

        if (!Instance.eventDictionary.TryGetValue(eventId, out baseEvents))
        {
            baseEvents = new GenericEvents2 <T, U>();
            Instance.eventDictionary.Add(eventId, baseEvents);
        }
        ((GenericEvents2 <T, U>)baseEvents).eventList.Add(listener);
    }
Beispiel #3
0
    public static void RemoveListener <T, U>(EventID eventId, EventFun2 <T, U> listener)
    {
        BaseEvents baseEvents;

        if (Instance.eventDictionary.TryGetValue(eventId, out baseEvents))
        {
            GenericEvents2 <T, U> impEvents = baseEvents as GenericEvents2 <T, U>;
            if (!impEvents.isLock)
            {
                impEvents.eventList.Remove(listener);
            }
            else
            {
                impEvents.deleteRequests.Add(listener);
            }
        }
    }