Beispiel #1
0
        //调用
        public void Run(string key, IGameEvent msg, Dictionary <string, GameEventHandlerItem> dic = null)
        {
            Dictionary <string, GameEventHandlerItem> refDic = null;

            if (dic == null)
            {
                refDic = eventsDic;
            }
            else
            {
                refDic = dic;
            }

            GameEventHandlerItem delegateItem = null;

            if (refDic.TryGetValue(key.ToUpper(), out delegateItem))
            {
                delegateItem?.Run(msg);
                if (delegateItem.ListenerCount == 0)
                {
                    refDic.Remove(key.ToUpper());
                }
            }
            else
            {
                MgrLog("NO REGISTER KEY:" + key);
            }
        }
Beispiel #2
0
        //注册
        public RegEventResult Register(
            string key,
            object reference,
            ELGame.GameEventHandler handler,
            int times = EGameConstL.Infinity,
            Dictionary <string, GameEventHandlerItem> dic = null)
        {
            Dictionary <string, GameEventHandlerItem> refDic = null;

            if (dic == null)
            {
                refDic = eventsDic;
            }
            else
            {
                refDic = dic;
            }

            //如果不传dic则默认是全局广播
            GameEventHandlerItem delegateItem = null;

            if (refDic.TryGetValue(key.ToUpper(), out delegateItem))
            {
                return(delegateItem.AddEventHandler(reference, handler, times));
            }
            else
            {
                //没有
                refDic.Add(key.ToUpper(), new GameEventHandlerItem(key, reference, handler, times));

                if (dic == null)
                {
                    MgrLog(string.Format("注册世界事件:{0}, 相应次数:{1}", key, times));
                }
                else
                {
                    MgrLog(string.Format("注册本地事件:{0}, 相应次数:{1}", key, times));
                }

                return(RegEventResult.Success);
            }
        }