private bool PlayKeyFrame()
    {
        if (_lockStepKeyFrameDataList.Count == 0)
        {
            // 数据还未接收完毕,继续等待
            return(false);
        }
        LockStepKeyFrameData lockStepKeyFrameData = _lockStepKeyFrameDataList.Values[0];

        if (lockStepKeyFrameData.KeyFrame == _clientFrame)
        {
            foreach (LockStepClientMsgItem LockStepClientMsgItem in lockStepKeyFrameData.ReceiveMsgList)
            {
                if (LockStepClientMsgItem.msgId == MsgID.SteerPositionRsp)
                {
                    SteerPositionRsp resp   = (SteerPositionRsp)LockStepClientMsgItem.msg;
                    GameEntity       entity = _context.CreateEntity();
                    entity.AddPlayerId(resp.PlayerId);
                    entity.AddSteerPosition(new Vector2(resp.X, resp.Y));
                    Log4U.LogDebug("LockStepClientMgr:FixedUpdate _clientFrame=", _clientFrame, " resp=", resp.ToString());
                }
            }
            _lockStepKeyFrameDataList.RemoveAt(0);
            _nearstServerKeyFrame = _clientFrame + Config.SYN_RATE_SERVER;
            _gameController.Execute();
            _clientFrame++;
        }
        return(true);
    }
    private void OnSteerPositionRsp(IMessage msg, object ext)
    {
        SteerPositionRsp steerPositionRsp = (SteerPositionRsp)msg;
        int serverKeyFrame = steerPositionRsp.KeyFrame;
        LockStepClientMsgItem lockStepClientMsgItem = new LockStepClientMsgItem(MsgID.SteerPositionRsp, msg);
        LockStepKeyFrameData  lockStepKeyFrameData;

        if (_lockStepKeyFrameDataList.ContainsKey(serverKeyFrame))
        {
            lockStepKeyFrameData = _lockStepKeyFrameDataList[serverKeyFrame];
        }
        else
        {
            lockStepKeyFrameData = new LockStepKeyFrameData(serverKeyFrame);
            _lockStepKeyFrameDataList.Add(serverKeyFrame, lockStepKeyFrameData);
        }
        lockStepKeyFrameData.AddLockStepClientMsgItem(lockStepClientMsgItem);
    }
 private void FixedUpdate()
 {
     //  2个客户端都登录后,才开始帧同步
     if (_loginInPlayerCount < 2)
     {
         return;
     }
     _nextKeyFrame = _currKeyFrame + Config.SYN_RATE_SERVER;
     if (_currFrame % Config.SYN_RATE_SERVER == 0)
     {
         // 当前关键帧结束
         LockStepEnd lockStepEnd = new LockStepEnd();
         lockStepEnd.KeyFrame = _nextKeyFrame;
         lockStepEnd.MsgTotal = _msgIndex;
         ServerUDPMgr.GetInstance().SendMsgToAll(MsgID.LockStepEnd, lockStepEnd);
         _currKeyFrame = _currFrame;
         _msgIndex     = 0;
     }
     if (_msgQueue.Count != 0)
     {
         foreach (LockStepServerMsgItem serverMsgItem in _msgQueue)
         {
             if (serverMsgItem.msgId == MsgID.SteerPositionReq)
             {
                 SteerPositionReq steerPositionReq = (SteerPositionReq)serverMsgItem.msg;
                 SteerPositionRsp steerPositionRsp = new SteerPositionRsp();
                 steerPositionRsp.PlayerId = serverMsgItem.sendPlayerId;
                 steerPositionRsp.X        = steerPositionReq.X;
                 steerPositionRsp.Y        = steerPositionReq.Y;
                 // 客户端将要执行该命令的帧
                 steerPositionRsp.KeyFrame = _nextKeyFrame;
                 steerPositionRsp.MsgIndex = _msgIndex;
                 ServerUDPMgr.GetInstance().SendMsgToAll(MsgID.SteerPositionRsp, steerPositionRsp);
                 _msgIndex++;
             }
         }
         _msgQueue.Clear();
     }
     _currFrame++;
 }