Beispiel #1
0
        void OnToSelectTeam(object sender, EventArgs arg)
        {
            ToSelectTeamArg targ = arg as ToSelectTeamArg;

            if (targ != null)
            {
                GamePlayer playerInfo = targ.playerInfo;
                GlobalClient.PlayerManager.Self = playerInfo;
                m_controller.SetSceneState(new SelectTeamSceneState(m_controller));
            }
        }
Beispiel #2
0
        public void OnMessage(MessageBuffer msg)
        {
            int cproto = msg.ReadInt();

            //Debug.Log(cproto);
            switch (cproto)
            {
            case cProto.CONNECT:
            {
                int id = msg.ReadInt();
                clientID = id;
                Debug.Log("玩家客户端id = " + id);
                //服务器已连接
                ServerOnConnectArg arg = new ServerOnConnectArg();
                arg.ClientID = id;
                m_context.FireEvent(this, EventType.EVT_SERVER_ON_CONNECT, arg);
            }
            break;

            case cProto.READY:
                break;

            //位置同步
            case cProto.SYNC_POS:
                int    clientId = msg.ReadInt();
                int    entityId = msg.ReadInt();
                string pos      = msg.ReadString();
                GameManager.instance.ViewManager.SyncPos(clientId, pos, entityId);
                //Debug.Log(string.Format("玩家 {0} ,pos = {1}", cRoleId ,pos));
                break;

            //同步关键帧k
            case cProto.TO_TEAM_SELECT:
            {
                int             playerID       = msg.ReadInt();
                string          playerName     = msg.ReadString();
                string          playerIconPath = msg.ReadString();
                GamePlayer      playerInfo     = new GamePlayer(playerID, playerName, playerIconPath);
                ToSelectTeamArg arg            = new ToSelectTeamArg();
                arg.playerInfo = playerInfo;
                m_context.FireEvent(this, EventType.EVT_TO_TEAM_SELECT, arg);
                break;
            }

            case cProto.SYNC_KEY:
                //读取服务器帧数
                int servFrameCount = msg.ReadInt();
                //Debug.LogWarning(string.Format("服务器关键帧={0}", servFrameCount));
                GlobalClient.KeyFrameManager.serverKeyFrameNo = servFrameCount;
                //当服务器帧数>=当前客户端帧数的时候,客户端本地帧才更新
                if (servFrameCount >= GlobalClient.KeyFrameManager.curKeyFrameNo)
                {
                    //解析出所有用户的KeyDataList
                    string keyStr = msg.ReadString();
                    //分号分离各个用户的KeyDataList;
                    string[] keyData = keyStr.Split(';');
                    for (int i = 0; i < keyData.Length; ++i)
                    {
                        if (keyData[i] == "")
                        {
                            continue;
                        }
                        KeyFrame kf = new KeyFrame(keyData[i]);
                        //插入关键帧管理器中
                        GlobalClient.KeyFrameManager.AddKeyData(servFrameCount, kf);
                    }
                }
                break;

            case cProto.START:
                //读取玩家列表
                string players = msg.ReadString();
                //创建所有玩家
                GameManager.instance.ViewManager.CreateAllPlayer(players);
                //初始化服务器关键帧为1
                GlobalClient.KeyFrameManager.serverKeyFrameNo = 0;
                //每50毫秒向服务器发送位置信息
                //TimerHeap.AddTimer(0, 50, SycMePos);
                //每100毫秒向服务器关键帧数据
                // TimerHeap.AddTimer(0, 100, SycKey);
                break;
            }
        }