//发送当前玩家状态 void SendPlayerState() { Player p = GlobalVariables.localPlayer; if (p != null) { Protocol.ClientLocalPlayerInfo info = new ClientLocalPlayerInfo(); info.info = p.AchievePlayerInfo(); GameMsg msg = new GameMsg(GameMsg.MsgType.ClientLocalPlayerInfo, info); Client.SendMessage(msg, UnityEngine.Networking.QosType.StateUpdate); } else { Debug.LogError("ClientAgent.SendPlayerState >> local player is null"); } }
void OnClientLocalState(ClientLocalPlayerInfo state, Connection conn) { if (conn.state == ConnState.InGame) { Player p = lm.GetPlayer(conn.playerId); if (p != null) { RemotePlayerController rp = p.GetComponent <RemotePlayerController>(); if (rp != null) { rp.ApplyRemoteInfo(state.info); } else {//???不应该发生 Debug.LogError("ServerAgent.OnClientLocalState >> player has no remote controller component"); } } else { //???不应该发生 Debug.LogError("ServerAgent.OnClientLocalState >> player doesn't exist"); } } }
void OnDateEvent(GameMsg msg, int connId) { if (connDict.ContainsKey(connId)) { Connection conn = connDict[connId]; if (conn == null) { //不应该发生 Debug.LogError("ServerAgent.OnDateEvent>> connection is null"); return; } // 设置conn的lastTime conn.lastRecvTime = DateTime.Now; if (msg.type == GameMsg.MsgType.JoinGameReq) { JoinGameReq req = msg.content as JoinGameReq; if (req != null) { OnJoinGameReq(req, conn); } } else if (msg.type == GameMsg.MsgType.ClientReady) { ClientReady ready = msg.content as ClientReady; if (ready != null) { OnClientReady(ready, conn); } } else if (msg.type == GameMsg.MsgType.QuitGameReq) { QuitGameReq quit = msg.content as QuitGameReq; if (quit != null) { OnClientQuit(quit, conn); } } else if (msg.type == GameMsg.MsgType.ClientLocalPlayerInfo) { ClientLocalPlayerInfo state = msg.content as ClientLocalPlayerInfo; if (state != null) { OnClientLocalState(state, conn); } } else if (msg.type == GameMsg.MsgType.Damage) { HitPlayer hit = msg.content as HitPlayer; if (hit != null) { OnDamage(hit, conn); } } else if (msg.type == GameMsg.MsgType.Shoot) { PlayerShoot shoot = msg.content as PlayerShoot; if (shoot != null) { OnShoot(shoot, conn); } } } }