Exemple #1
0
        internal bool DispatchEvent <T, T1, T2, T3, T4>(string _eventName, ref T t, T1 t1, T2 t2, T3 t3, T4 t4)
        {
            LinkedList <SuperEventListenerUnit> linkedList = DispatchEventReal <SuperFunctionCallBackV4 <T, T1, T2, T3, T4> >(_eventName);

            if (linkedList != null)
            {
                while (linkedList.First != null)
                {
                    LinkedListNode <SuperEventListenerUnit> node = linkedList.First;

                    SuperEventListenerUnit unit = node.Value;

                    SuperFunctionCallBackV4 <T, T1, T2, T3, T4> cb = unit.callBack as SuperFunctionCallBackV4 <T, T1, T2, T3, T4>;

                    cb(unit.index, ref t, t1, t2, t3, t4);

                    ReleaseLinkedListNode(node);

                    linkedList.RemoveFirst();
                }

                ReleaseLinkedList(linkedList);

                return(true);
            }
            else
            {
                return(false);
            }
        }
        internal int AddListener(string _eventName, Action <SuperEvent> _callBack)
        {
            SuperEventListenerUnit unit = new SuperEventListenerUnit(nowIndex, _eventName, _callBack);

            nowIndex++;

            dicWithID.Add(unit.index, unit);

            Dictionary <Action <SuperEvent>, SuperEventListenerUnit> dic;

            if (dicWithEvent.ContainsKey(_eventName))
            {
                dic = dicWithEvent[_eventName];
            }
            else
            {
                dic = new Dictionary <Action <SuperEvent>, SuperEventListenerUnit>();

                dicWithEvent.Add(_eventName, dic);
            }

            dic.Add(_callBack, unit);

            return(unit.index);
        }
Exemple #3
0
        internal bool DispatchEvent <T1>(string _eventName, T1 t1)
        {
            LinkedList <SuperEventListenerUnit> linkedList = DispatchEventReal <SuperFunctionCallBack1 <T1> >(_eventName);

            if (linkedList != null)
            {
                while (linkedList.First != null)
                {
                    LinkedListNode <SuperEventListenerUnit> node = linkedList.First;

                    SuperEventListenerUnit unit = node.Value;

                    SuperFunctionCallBack1 <T1> cb = unit.callBack as SuperFunctionCallBack1 <T1>;

                    cb(unit.index, t1);

                    ReleaseLinkedListNode(node);

                    linkedList.RemoveFirst();
                }

                ReleaseLinkedList(linkedList);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #4
0
        internal int AddListener <T>(string _eventName, EventCallBack <T> _callBack) where T : struct
        {
            SuperEventListenerUnit <T> unit = new SuperEventListenerUnit <T>(nowIndex, _eventName, _callBack);

            nowIndex++;

            dicWithID.Add(unit.index, unit);

            Dictionary <Delegate, SuperEventListenerUnitBase> dic;

            if (dicWithEvent.ContainsKey(_eventName))
            {
                dic = dicWithEvent[_eventName];
            }
            else
            {
                dic = new Dictionary <Delegate, SuperEventListenerUnitBase>();

                dicWithEvent.Add(_eventName, dic);
            }

            dic.Add(_callBack, unit);

            return(unit.index);
        }
Exemple #5
0
        private LinkedListNode <SuperEventListenerUnit> GetLinkedListNode(SuperEventListenerUnit _unit)
        {
            LinkedListNode <SuperEventListenerUnit> linkedListNode;

            if (pool1.Count > 0)
            {
                linkedListNode = pool1.Dequeue();

                linkedListNode.Value = _unit;
            }
            else
            {
                linkedListNode = new LinkedListNode <SuperEventListenerUnit>(_unit);
            }

            return(linkedListNode);
        }
        internal void RemoveListener(int _index)
        {
            if (dicWithID.ContainsKey(_index))
            {
                SuperEventListenerUnit unit = dicWithID[_index];

                dicWithID.Remove(_index);

                Dictionary <Action <SuperEvent>, SuperEventListenerUnit> dic = dicWithEvent[unit.eventName];

                dic.Remove(unit.callBack);

                if (dic.Count == 0)
                {
                    dicWithEvent.Remove(unit.eventName);
                }
            }
        }
        internal void RemoveListener(string _eventName, Action <SuperEvent> _callBack)
        {
            if (dicWithEvent.ContainsKey(_eventName))
            {
                Dictionary <Action <SuperEvent>, SuperEventListenerUnit> dic = dicWithEvent[_eventName];

                if (dic.ContainsKey(_callBack))
                {
                    SuperEventListenerUnit unit = dic[_callBack];

                    dicWithID.Remove(unit.index);

                    dic.Remove(_callBack);

                    if (dic.Count == 0)
                    {
                        dicWithEvent.Remove(_eventName);
                    }
                }
            }
        }
Exemple #8
0
        internal int AddListenerReal(string _eventName, Delegate _callBack, int _priority)
        {
            SuperEventListenerUnit unit = new SuperEventListenerUnit(nowIndex, _eventName, _callBack, _priority);

            nowIndex++;

            dicWithID.Add(unit.index, unit);

            Dictionary <Delegate, SuperEventListenerUnit> dic;

            if (!dicWithEvent.TryGetValue(_eventName, out dic))
            {
                dic = GetDic();

                dicWithEvent.Add(_eventName, dic);
            }

            dic.Add(_callBack, unit);

            return(unit.index);
        }
Exemple #9
0
        private LinkedList <SuperEventListenerUnit> DispatchEventReal <T>(string _eventName)
        {
            LinkedList <SuperEventListenerUnit> linkedList = null;

            Dictionary <Delegate, SuperEventListenerUnit> dic;

            if (dicWithEvent.TryGetValue(_eventName, out dic))
            {
                IEnumerator <KeyValuePair <Delegate, SuperEventListenerUnit> > enumerator = dic.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    if (enumerator.Current.Key is T)
                    {
                        if (linkedList == null)
                        {
                            linkedList = GetLinkedList();
                        }

                        KeyValuePair <Delegate, SuperEventListenerUnit> pair = enumerator.Current;

                        int priority = pair.Value.priority;

                        LinkedListNode <SuperEventListenerUnit> addNode = GetLinkedListNode(pair.Value);

                        LinkedListNode <SuperEventListenerUnit> lastNode = linkedList.First;

                        if (lastNode == null)
                        {
                            linkedList.AddFirst(addNode);
                        }
                        else
                        {
                            while (true)
                            {
                                SuperEventListenerUnit unit = lastNode.Value;

                                if (priority > unit.priority)
                                {
                                    lastNode = lastNode.Next;

                                    if (lastNode == null)
                                    {
                                        linkedList.AddLast(addNode);

                                        break;
                                    }
                                }
                                else
                                {
                                    linkedList.AddBefore(lastNode, addNode);

                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(linkedList);
        }