public void Rem(string eventName, OnEvent onEventp)
        {
            OnEvent onEvent;

            eventsDic.TryGetValue(eventName, out onEvent);

            if (onEvent == null)
            {
                Debug.LogWarningFormat("Send EventName {0} is not in m_dicEvent!", eventName);
            }
            else
            {
                List <ListenerSorter> list;
                sortDic.TryGetValue(eventName, out list);

                if (list != null)
                {
                    for (int i = list.Count - 1; i >= 0; i--)
                    {
                        ListenerSorter listenerSorter = list[i];

                        if (listenerSorter.deleg.Method.Equals(onEventp.Method))
                        {
                            list.RemoveAt(i);

                            Debug.LogFormat("rem sortDic eventName:{0} Target:{1} Method:{2}", eventName, onEventp.Target, onEventp.Method);
                        }
                    }
                }

                Delegate[] invocationList = onEvent.GetInvocationList();

                for (int i = invocationList.Length - 1; i >= 0; i--)
                {
                    if (invocationList[i].Method.Equals(onEventp.Method))
                    {
                        eventsDic[eventName] -= onEventp;

                        Debug.LogFormat("rem eventsDic eventName:{0} Target:{1} Method:{2}", eventName, onEventp.Target, onEventp.Method);
                    }
                }
            }
        }
示例#2
0
        public void Rem(string eventName, OnEvent onEventp)
        {
            OnEvent onEvent;

            eventsDic.TryGetValue(eventName, out onEvent);

            if (onEvent == null)
            {
                Debug.LogWarning("EventManager.Send EventName " + eventName + " is not in m_dicEvents!!");
            }
            else
            {
                List <ListenerSorter> list;
                sortDic.TryGetValue(eventName, out list);

                if (list != null)
                {
                    for (int i = list.Count - 1; i >= 0; i--)
                    {
                        ListenerSorter listenerSorter = list[i];
                        if (listenerSorter.deleg.Method.Equals(onEventp.Method))
                        {
                            list.RemoveAt(i);
                            Debug.Log("rem sortDic " + "eventName " + eventName + "Target " + onEventp.Target + " Method " + onEventp.Method);
                        }
                    }
                }

                System.Delegate[] invocationList = onEvent.GetInvocationList();

                for (int i = invocationList.Length - 1; i >= 0; i--)
                {
                    if (invocationList[i].Method.Equals(onEventp.Method))
                    {
                        Debug.Log("rem eventsDic " + "eventName " + eventName + "Target " + onEventp.Target + " Method " + onEventp.Method);

                        eventsDic[eventName] -= onEventp;
                    }
                }
            }
        }
        public void RemByTargetAll(object target)
        {
            List <string> keyList = new List <string>(eventsDic.Keys);

            foreach (string eventName in keyList)
            {
                OnEvent onEvent;
                eventsDic.TryGetValue(eventName, out onEvent);

                if (onEvent == null)
                {
                    continue;
                }

                Delegate[] invocationList = onEvent.GetInvocationList();
                for (int i = invocationList.Length - 1; i >= 0; i--)
                {
                    if (invocationList[i].Target.Equals(target))
                    {
                        eventsDic[eventName] -= (OnEvent)invocationList[i];
                    }
                }

                List <ListenerSorter> list;
                sortDic.TryGetValue(eventName, out list);

                if (list != null)
                {
                    for (int i = list.Count - 1; i >= 0; i--)
                    {
                        ListenerSorter listenerSorter = list[i];
                        if (listenerSorter.deleg.Target.Equals(target))
                        {
                            list.RemoveAt(i);

                            Debug.LogFormat("rem eventName {0} Target {1}", eventName, target);
                        }
                    }
                } //end if (list != null)
            }     //foreach (string eventName in keyList)
        }
        public void RemByTarget(string eventName, object target)
        {
            OnEvent onEvent;

            eventsDic.TryGetValue(eventName, out onEvent);

            if (onEvent == null)
            {
                Debug.LogWarningFormat(" EventName {0} is not in eventsDic!", eventName);
            }
            else
            {
                Delegate[] invocationList = eventsDic[eventName].GetInvocationList();

                for (int i = invocationList.Length - 1; i >= 0; i--)
                {
                    if (invocationList[i].Target.Equals(target))
                    {
                        eventsDic[eventName] -= (OnEvent)invocationList[i];
                    }
                }
            }

            List <ListenerSorter> list;

            sortDic.TryGetValue(eventName, out list);

            if (list != null)
            {
                for (int i = list.Count - 1; i >= 0; i--)
                {
                    ListenerSorter listenerSorter = list[i];
                    if (listenerSorter.deleg.Target.Equals(target))
                    {
                        list.RemoveAt(i);

                        Debug.LogFormat("rem eventName {0} Target {1}", eventName, target);
                    }
                }
            }
        }
示例#5
0
        public void RemByTarget(string eventName, object target)
        {
            OnEvent onEvent;

            eventsDic.TryGetValue(eventName, out onEvent);

            if (onEvent == null)
            {
                Debug.LogWarning("EventManager.Send EventName " + eventName + " is not in eventsDic!!");
            }
            else
            {
                System.Delegate[] invocationList = eventsDic[eventName].GetInvocationList();

                for (int i = invocationList.Length - 1; i >= 0; i--)
                {
                    if (invocationList[i].Target.Equals(target))
                    {
                        eventsDic[eventName] -= (OnEvent)invocationList[i];
                    }
                }
            }

            List <ListenerSorter> list;

            sortDic.TryGetValue(eventName, out list);

            if (list != null)
            {
                for (int i = list.Count - 1; i >= 0; i--)
                {
                    ListenerSorter listenerSorter = list[i];
                    if (listenerSorter.deleg.Target.Equals(target))
                    {
                        list.RemoveAt(i);
                        Debug.Log("rem" + "eventName " + eventName + "Target " + target);
                    }
                }
            }
        }
示例#6
0
        public override bool Equals(object obj)
        {
            ListenerSorter listenerSorter = (ListenerSorter)obj;

            return(deleg.Equals(listenerSorter.deleg));
        }
示例#7
0
        public void Add(string eventName, OnEvent onEventp, int level)
        {
            OnEvent onEvent;

            eventsDic.TryGetValue(eventName, out onEvent);

            List <ListenerSorter> list;

            sortDic.TryGetValue(eventName, out list);

            if (onEvent != null && list == null)
            {
                Debug.LogError("eventName " + eventName + " is not all target in sortDic!!!!");
                return;
            }

            if (onEvent == null)
            {
                if (eventsDic.ContainsKey(eventName))
                {
                    eventsDic.Remove(eventName);
                }
                eventsDic.Add(eventName, onEventp);
            }
            else
            {
                eventsDic[eventName] += onEventp;
            }

            ListenerSorter listenerSorter = new ListenerSorter(level, onEventp);

            if (list == null)
            {
                list = new List <ListenerSorter>();
                sortDic.Add(eventName, list);
            }

            for (int i = list.Count - 1; i >= 0; i--)
            {
                if (listenerSorter.Equals(list[i]))
                {
                    Debug.LogWarning("Added Again >>>>>>>>>>>>>" + eventName);
                    return;
                }
            }

            list.Add(listenerSorter);
            list.Sort(listenerSorterComparer);

            System.Delegate[] invocationList = eventsDic[eventName].GetInvocationList();

            for (int i = invocationList.Length - 1; i >= 0; i--)
            {
                eventsDic[eventName] -= (OnEvent)invocationList[i];
            }

            for (int i = 0; i < list.Count; i++)
            {
                eventsDic[eventName] += (OnEvent)list[i].deleg;
            }
        }