Пример #1
0
        private List <SuperFunctionUnit> DispatchEventReal <T>(GameObject _target, string _eventName)
        {
            List <SuperFunctionUnit> result = null;

            Dictionary <string, List <SuperFunctionUnit> > tmpDic;

            if (dic2.TryGetValue(_target, out tmpDic))
            {
                List <SuperFunctionUnit> tmpList;

                if (tmpDic.TryGetValue(_eventName, out tmpList))
                {
                    for (int i = 0; i < tmpList.Count; i++)
                    {
                        SuperFunctionUnit unit = tmpList[i];

                        if (unit.callBack is T)
                        {
                            if (result == null)
                            {
                                result = GetList();
                            }

                            result.Add(unit);
                        }
                    }
                }
            }

            return(result);
        }
Пример #2
0
        public void DestroyGameObject(GameObject _target)
        {
            Dictionary <string, List <SuperFunctionUnit> > tmpDic;

            if (dic2.TryGetValue(_target, out tmpDic))
            {
                dic2.Remove(_target);

                IEnumerator <List <SuperFunctionUnit> > enumerator = tmpDic.Values.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    List <SuperFunctionUnit> tmpList = enumerator.Current;

                    for (int i = 0; i < tmpList.Count; i++)
                    {
                        SuperFunctionUnit unit = tmpList[i];

                        dic.Remove(unit.index);
                    }

                    tmpList.Clear();

                    ReleaseList(tmpList);
                }

                tmpDic.Clear();

                ReleaseDic(tmpDic);
            }
        }
Пример #3
0
        public bool DispatchEvent <T1, T2, T3>(GameObject _target, string _eventName, T1 t1, T2 t2, T3 t3)
        {
            List <SuperFunctionUnit> unitList = DispatchEventReal <SuperFunctionCallBack3 <T1, T2, T3> >(_target, _eventName);

            if (unitList != null)
            {
                for (int i = 0; i < unitList.Count; i++)
                {
                    SuperFunctionUnit unit = unitList[i];

                    if (unit.isOnce)
                    {
                        RemoveEventListener(unit.index);
                    }

                    SuperFunctionCallBack3 <T1, T2, T3> cb = unit.callBack as SuperFunctionCallBack3 <T1, T2, T3>;

                    cb(unit.index, t1, t2, t3);
                }

                unitList.Clear();

                ReleaseList(unitList);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #4
0
        public bool DispatchEvent <T, T1, T2, T3, T4>(GameObject _target, string _eventName, ref T _t, T1 _t1, T2 _t2, T3 _t3, T4 _t4)
        {
            List <SuperFunctionUnit> unitList = DispatchEventReal <SuperFunctionCallBackV4 <T, T1, T2, T3, T4> >(_target, _eventName);

            if (unitList != null)
            {
                for (int i = 0; i < unitList.Count; i++)
                {
                    SuperFunctionUnit unit = unitList[i];

                    if (unit.isOnce)
                    {
                        RemoveEventListener(unit.index);
                    }

                    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);
                }

                unitList.Clear();

                ReleaseList(unitList);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #5
0
        public void RemoveEventListener(GameObject _target, string _eventName)
        {
            Dictionary <string, List <SuperFunctionUnit> > tmpDic;

            if (dic2.TryGetValue(_target, out tmpDic))
            {
                List <SuperFunctionUnit> list;

                if (tmpDic.TryGetValue(_eventName, out list))
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        SuperFunctionUnit unit = list[i];

                        dic.Remove(unit.index);
                    }

                    list.Clear();

                    ReleaseList(list);

                    tmpDic.Remove(_eventName);

                    if (tmpDic.Count == 0)
                    {
                        ReleaseDic(tmpDic);

                        DestroyControl(_target);
                    }
                }
            }
        }
Пример #6
0
        public void DestroyGameObject(GameObject _target)
        {
            if (dic2.ContainsKey(_target))
            {
                Dictionary <string, List <SuperFunctionUnit> > tmpDic = dic2[_target];

                dic2.Remove(_target);

                Dictionary <string, List <SuperFunctionUnit> > .ValueCollection.Enumerator enumerator = tmpDic.Values.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    List <SuperFunctionUnit> tmpList = enumerator.Current;

                    for (int i = 0; i < tmpList.Count; i++)
                    {
                        SuperFunctionUnit unit = tmpList[i];

                        dic.Remove(unit.index);

                        if (removeDelegate != null)
                        {
                            removeDelegate(unit.index);
                        }
                    }
                }
            }
        }
Пример #7
0
        private int AddEventListener(GameObject _target, string _eventName, Delegate _callBack, bool _isOnce)
        {
            int result = GetIndex();

            SuperFunctionUnit unit = new SuperFunctionUnit(_target, _eventName, _callBack, result, _isOnce);

            dic.Add(result, unit);

            Dictionary <string, List <SuperFunctionUnit> > tmpDic;

            if (!dic2.TryGetValue(_target, out tmpDic))
            {
                _target.AddComponent <SuperFunctionControl>();

                tmpDic = GetDic();

                dic2.Add(_target, tmpDic);
            }

            List <SuperFunctionUnit> tmpList;

            if (!tmpDic.TryGetValue(_eventName, out tmpList))
            {
                tmpList = GetList();

                tmpDic.Add(_eventName, tmpList);
            }

            tmpList.Add(unit);

            return(result);
        }
Пример #8
0
        public void RemoveEventListener(GameObject _target, string _eventName)
        {
            if (dic2.ContainsKey(_target))
            {
                Dictionary <string, List <SuperFunctionUnit> > tmpDic = dic2[_target];

                if (tmpDic.ContainsKey(_eventName))
                {
                    List <SuperFunctionUnit> list = tmpDic[_eventName];

                    for (int i = 0; i < list.Count; i++)
                    {
                        SuperFunctionUnit unit = list[i];

                        dic.Remove(unit.index);

                        if (removeDelegate != null)
                        {
                            removeDelegate(unit.index);
                        }
                    }

                    tmpDic.Remove(_eventName);

                    if (tmpDic.Count == 0)
                    {
                        DestroyControl(_target);
                    }
                }
            }
        }
Пример #9
0
        public void RemoveEventListener(int _index)
        {
            if (dic.ContainsKey(_index))
            {
                SuperFunctionUnit unit = dic[_index];

                dic.Remove(_index);

                if (removeDelegate != null)
                {
                    removeDelegate(_index);
                }

                Dictionary <string, List <SuperFunctionUnit> > tmpDic = dic2[unit.target];

                List <SuperFunctionUnit> tmpList = tmpDic[unit.eventName];

                tmpList.Remove(unit);

                if (tmpList.Count == 0)
                {
                    tmpDic.Remove(unit.eventName);

                    if (tmpDic.Count == 0)
                    {
                        DestroyControl(unit.target);
                    }
                }
            }
        }
Пример #10
0
        public void DispatchEvent <T1, T2, T3, T4>(GameObject _target, string _eventName, T1 t1, T2 t2, T3 t3, T4 t4)
        {
            if (dic2.ContainsKey(_target))
            {
                Dictionary <string, List <SuperFunctionUnit> > tmpDic = dic2[_target];

                if (tmpDic.ContainsKey(_eventName))
                {
                    List <SuperFunctionUnit> tmpList = tmpDic[_eventName];

                    LinkedList <SuperFunctionUnit> unitList = null;

                    for (int i = 0; i < tmpList.Count; i++)
                    {
                        SuperFunctionUnit unit = tmpList[i];

                        if (unit.callBack is SuperFunctionCallBack4 <T1, T2, T3, T4> )
                        {
                            if (unitList == null)
                            {
                                unitList = new LinkedList <SuperFunctionUnit>();
                            }

                            unitList.AddLast(unit);
                        }
                    }

                    if (unitList != null)
                    {
                        LinkedList <SuperFunctionUnit> .Enumerator enumerator = unitList.GetEnumerator();

                        while (enumerator.MoveNext())
                        {
                            if (enumerator.Current.isOnce)
                            {
                                RemoveEventListener(enumerator.Current.index);
                            }

                            SuperFunctionCallBack4 <T1, T2, T3, T4> cb = enumerator.Current.callBack as SuperFunctionCallBack4 <T1, T2, T3, T4>;

                            cb(enumerator.Current.index, t1, t2, t3, t4);
                        }
                    }
                }
            }
        }
Пример #11
0
        private void RemoveEventListenerReal(GameObject _target, string _eventName, Delegate _callBack)
        {
            if (dic2.ContainsKey(_target))
            {
                Dictionary <string, List <SuperFunctionUnit> > tmpDic = dic2[_target];

                if (tmpDic.ContainsKey(_eventName))
                {
                    List <SuperFunctionUnit> list = tmpDic[_eventName];

                    for (int i = 0; i < list.Count; i++)
                    {
                        SuperFunctionUnit unit = list[i];

                        if (unit.callBack == _callBack)
                        {
                            dic.Remove(unit.index);

                            if (removeDelegate != null)
                            {
                                removeDelegate(unit.index);
                            }

                            list.RemoveAt(i);

                            break;
                        }
                    }

                    if (list.Count == 0)
                    {
                        tmpDic.Remove(_eventName);

                        if (tmpDic.Count == 0)
                        {
                            DestroyControl(_target);
                        }
                    }
                }
            }
        }
Пример #12
0
        private void RemoveEventListenerReal(GameObject _target, string _eventName, Delegate _callBack)
        {
            Dictionary <string, List <SuperFunctionUnit> > tmpDic;

            if (dic2.TryGetValue(_target, out tmpDic))
            {
                List <SuperFunctionUnit> list;

                if (tmpDic.TryGetValue(_eventName, out list))
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        SuperFunctionUnit unit = list[i];

                        if (unit.callBack == _callBack)
                        {
                            dic.Remove(unit.index);

                            list.RemoveAt(i);

                            break;
                        }
                    }

                    if (list.Count == 0)
                    {
                        ReleaseList(list);

                        tmpDic.Remove(_eventName);

                        if (tmpDic.Count == 0)
                        {
                            ReleaseDic(tmpDic);

                            DestroyControl(_target);
                        }
                    }
                }
            }
        }
Пример #13
0
        private int AddEventListener(GameObject _target, string _eventName, Delegate _callBack, bool _isOnce)
        {
            int result = GetIndex();

            SuperFunctionUnit unit = new SuperFunctionUnit(_target, _eventName, _callBack, result, _isOnce);

            dic.Add(result, unit);

            Dictionary <string, List <SuperFunctionUnit> > tmpDic;

            if (dic2.ContainsKey(_target))
            {
                tmpDic = dic2[_target];
            }
            else
            {
                _target.AddComponent <SuperFunctionControl>();

                tmpDic = new Dictionary <string, List <SuperFunctionUnit> >();

                dic2.Add(_target, tmpDic);
            }

            List <SuperFunctionUnit> tmpList;

            if (tmpDic.ContainsKey(_eventName))
            {
                tmpList = tmpDic[_eventName];
            }
            else
            {
                tmpList = new List <SuperFunctionUnit>();

                tmpDic.Add(_eventName, tmpList);
            }

            tmpList.Add(unit);

            return(result);
        }