예제 #1
0
    //发送当前玩家状态
    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");
        }
    }
예제 #2
0
 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");
         }
     }
 }
예제 #3
0
    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);
                }
            }
        }
    }