示例#1
0
 /// <summary>
 /// 在Update处理所有的协议,避免多线程可能引起的不能在协议回调的时候操作UI或者其他的只能在主线程做的事情
 /// </summary>
 void Update()
 {
     while (mListProtoPacket.Count > 0)
     {
         ProtoBase_S2C protoData = mListProtoPacket[0];
         HandlePacket(protoData);
         mListProtoPacket.RemoveAt(0);
     }
 }
示例#2
0
 /// <summary>
 /// 处理协议包
 /// </summary>
 /// <param name="resp"></param>
 void HandlePacket(ProtoBase_S2C resp)
 {
     //触发所有侦听了这个协议的函数
     for (int i = 0; i < mListPacketDataHandle.Count; i++)
     {
         PacketHandle handle = mListPacketDataHandle[i];
         if (handle.packetType == resp.GetType())
         {
             if (handle.handleFuntion != null)
             {
                 handle.handleFuntion(resp);
             }
         }
     }
 }
 /// <summary>
 /// 处理协议包
 /// </summary>
 /// <param name="resp"></param>
 void HandlePacket(ProtoBase_S2C resp)
 {
     //触发所有侦听了这个协议的函数
     for (int i = 0; i < mListPacketDataHandle.Count; i++)
     {
         PacketHandle handle = mListPacketDataHandle[i];
         if (handle.packetType == resp.GetType())
         {
             if (handle.handleFuntion != null)
             {
                 handle.handleFuntion(resp);
             }
         }
     }
 }
示例#4
0
    /// <summary>
    /// 在刚好接收完一个完整的协议的时候调用,构造一个完整的协议包
    /// </summary>
    public void CreatePacketFromBuffer()
    {
        byte[] packetBytes = new byte[BodyLength];
        //从缓存里获取属于这个协议的内容
        Array.Copy(protobuffBytes, Header_Length, packetBytes, 0, packetBytes.Length);
        byte[] protoCodeBytes = new byte[4];
        Array.Copy(packetBytes, 0, protoCodeBytes, 0, protoCodeBytes.Length); //协议的前面四位为协议号
        int           protoCode = BitConverter.ToInt32(protoCodeBytes, 0);
        ProtoBase_S2C decoder   = ProtoMapper.GetProtoDecoder(protoCode);

        if (decoder != null)
        {
            decoder.Decode(packetBytes);
            ProtoPacketQueueManager.instance.AddPacket(decoder);
        }
    }
示例#5
0
    public static ProtoBase_S2C GetProtoDecoder(int protoCode)
    {
        if (!mProtoDictionary.ContainsKey(protoCode))
        {
            Debug.LogError("Proto " + protoCode + " doesn't have any decoder ");
            return(null);
        }
        else
        {
            Type decoderType = mProtoDictionary[protoCode];

            ProtoBase_S2C decoder = null;
            decoder = decoderType.Assembly.CreateInstance(decoderType.Name) as ProtoBase_S2C;

            return(decoder);
        }
    }
示例#6
0
 public void AddPacket(ProtoBase_S2C packet)
 {
     mListProtoPacket.Add(packet);
 }
示例#7
0
    void OnGetPlayerInfoResp(ProtoBase_S2C data)
    {
        GetUserInfo_S2C info = (GetUserInfo_S2C)data;

        Debug.Log("get player info :  userId  " + info.userId + "    name " + info.name + " age " + info.age);
    }
示例#8
0
    void OnChatResp(ProtoBase_S2C data)
    {
        Chat_S2C chat = (Chat_S2C)data;

        Debug.Log("chat:  userId  " + chat.userId + "   chat name " + chat.text);
    }
示例#9
0
 void OnGetPlayerInfoResp(ProtoBase_S2C data)
 {
     GetUserInfo_S2C info = (GetUserInfo_S2C)data;
     Debug.Log("get player info :  userId  " + info.userId + "    name " + info.name+" age "+info.age);
 }
示例#10
0
 void OnChatResp(ProtoBase_S2C data)
 {
     Chat_S2C chat = (Chat_S2C) data;
     Debug.Log("chat:  userId  " + chat.userId +"   chat name " + chat.text);
 }
 public void AddPacket(ProtoBase_S2C packet)
 {
     mListProtoPacket.Add(packet);
 }