Пример #1
0
 /// <summary>
 /// 接收消息池处理方法,每帧调用一次
 /// </summary>
 private void ReciveMsgHandler()
 {
     while (!ReciveMsgPool.IsEmpty)
     {
         ReciveMsgVO msg = null;
         ReciveMsgPool.TryDequeue(out msg);
         if (msg == null)
         {
             continue;
         }
         MsgNoS2C msgNo = (MsgNoS2C)msg.channel;
         ClientAIMgr.Instance.ShowMsgLog(string.Format("消息:{0} 消息号:{1}", msgNo.ToString(), msg.channel));
         if (msgHandleDic.ContainsKey(msgNo))
         {
             for (int i = 0; i < msgHandleDic[msgNo].Count; i++)
             {
                 try
                 {
                     msgHandleDic[msgNo][i](msg.bytes);
                 }
                 catch (System.Exception e)
                 {
                     Debug.LogError(string.Format("{0} {1}", e.Message, e.StackTrace));
                 }
             }
         }
     }
 }
Пример #2
0
 /// <summary>
 /// 添加带序号的消息映射响应
 /// </summary>
 /// <param name="msgNo"></param>
 /// <param name="msgHandler"></param>
 public void AddMsgWithIndex(MsgNoS2C msgNo, MsgWithIndexHandlerFun msgHandler)
 {
     if (!msgWithIndexHandleDic.ContainsKey(msgNo))
     {
         msgWithIndexHandleDic.Add(msgNo, new List <MsgWithIndexHandlerFun>());
     }
     msgWithIndexHandleDic[msgNo].Add(msgHandler);
 }
Пример #3
0
 /// <summary>
 /// 移除消息映射
 /// </summary>
 /// <param PlayerName="msgNo">消息号</param>
 /// <param PlayerName="msgHandler">消息回调方法</param>
 public void RemoveMsgHandler(MsgNoS2C msgNo, MsgHandlerFun msgHandler)
 {
     if (!msgHandleDic.ContainsKey(msgNo))
     {
         return;
     }
     for (int i = 0; i < msgHandleDic[msgNo].Count; i++)
     {
         if (msgHandleDic[msgNo][i] == msgHandler)
         {
             msgHandleDic[msgNo].Remove(msgHandler);
             return;
         }
     }
 }