Example #1
0
 /// <summary>
 /// 所有人已客户端资源加载完成,服务器通知一起战斗开始
 /// </summary>
 /// <param name="pack"></param>
 public void OnS2CFightLoadingStart(KcpNetPack pack)
 {
     _isGameStarted = true;
     _UnityUdpSocket.UnregisterHandler(MsgID.S2CFightStart, OnS2CFightLoadingStart);
     lockstep.CheckGameStart();
     Debug.LogFormat("Battle Started!");
 }
Example #2
0
 public void Send(KcpNetPack pack)
 {
     if (kcpsocket != null)
     {
         kcpsocket.SendPack(pack);
     }
 }
    /// <summary>
    /// 帧同步信息
    /// </summary>
    public void OnS2CFrameInfo(KcpNetPack pack)
    {
        PB_FrameInfo          mFrameInfo = PB_FrameInfo.Parser.ParseFrom(pack.BodyBuffer.Bytes);
        uint                  frameindex = mFrameInfo.FrameIndex;
        List <PB_PlayerFrame> list       = new List <PB_PlayerFrame>();

        for (int i = 0; i < mFrameInfo.Inputs.Count; i++)
        {
            list.Add(mFrameInfo.Inputs[i]);
        }
        TrueSyncManager.Instance.AddOneFrame(frameindex, list);
    }
Example #4
0
 public bool HandleMsg(KcpNetPack pack)
 {
     try
     {
         Handle handler = null;
         MsgID  msgID   = (MsgID)pack.HeadID;
         //Debug.LogFormat("msg.pack.id = {0}", pack.MessageID);
         if (msgHandle.TryGetValue(msgID, out handler))
         {
             if (handler != null)
             {
                 handler(pack);
                 pack.BodyBuffer.Dispose();
                 pack.HeaderBuffer.Dispose();
                 return(true);
             }
             else
             {
                 Debug.LogWarningFormat("Error -- find message handler = null with MessageID: {0}", msgID);
             }
         }
         else
         {
             if (msgID != MsgID.HeartbeatId)
             {
                 //TODO:主要是因为在PVP时,有可能出错一方发广播消息,另一方还没有注册此消息,引发错误
                 //后面改回来,规范流程
                 Debug.LogErrorFormat("Error -- Can't find message handler with MessageID: {0}", msgID);
             }
         }
     }
     catch (System.Exception ex)
     {
         Debug.LogException(ex);
     }
     return(false);
 }
Example #5
0
 /// <summary>
 /// 战斗失败/胜利后退出战斗,及结算信息
 /// </summary>
 void OnS2CFightEnd(KcpNetPack pack)
 {
     FightEnd();
     LoadingManager.LoadSceneAsync(SceneConfig.InitAgain);
 }
Example #6
0
    public void Send <T>(MsgID msgID, T content) where T : Google.Protobuf.IMessage
    {
        KcpNetPack pack = KcpNetPack.SerializeToPack(content, (ushort)msgID);

        Send(pack);
    }