예제 #1
0
        public bool AddListener <Arg0, Arg1>(string _evtName, Action <Arg0, Arg1> _evt)
        {
            if (string.IsNullOrEmpty(_evtName) || _evt == null)
            {
                return(false);
            }

            CZEvent <Arg0, Arg1> czEvt;

            if (eventsDic.TryGetValue(_evtName, out ICZEvent eventBase))
            {
                czEvt = eventBase as CZEvent <Arg0, Arg1>;
                if (czEvt == null)
                {
                    Debug.LogWarning("已存在参数数量不符的同名事件,故无法新增事件");
                    return(false);
                }
            }
            else
            {
                eventsDic[_evtName] = czEvt = new CZEvent <Arg0, Arg1>();
            }

            czEvt.AddListener(_evt);
            return(true);
        }
예제 #2
0
        public void DispatchEvent <Arg0, Arg1, Arg2, Arg3>(string _evtName, Arg0 _arg0, Arg1 _arg1, Arg2 _arg2, Arg3 _arg3)
        {
            if (string.IsNullOrEmpty(_evtName))
            {
                Debug.Log("事件名不能为空");
                return;
            }

            CZEvent <Arg0, Arg1, Arg2, Arg3> czEvt = null;

            if (eventsDic.TryGetValue(_evtName, out ICZEvent tempEvt))
            {
                czEvt = tempEvt as CZEvent <Arg0, Arg1, Arg2, Arg3>;
            }

            if (czEvt == null)
            {
                Debug.Log(" \"" + _evtName + " \"事件所需参数类型或个数不合理, 或者该事件不存在");
            }
            else
            {
                czEvt.Invoke(_arg0, _arg1, _arg2, _arg3);
            }
        }