예제 #1
0
    void OnInitClientGame(InitServerGameInfo info)
    {
        if (!initRecieved)
        {
            PlayerInfo localInfo = info.clientLocalPlayer;
            if (localInfo != null)
            {
                Player localPlayer = lm.AddPlayer(ControllerType.Local, localInfo.id, localInfo.name);
                localPlayer.transform.position = new Vector3(localInfo.positionX, localInfo.positionY, localInfo.positionZ);

                foreach (PlayerInfo remoteInfo in info.elsePlayers)
                {
                    if (remoteInfo.id != localInfo.id)
                    {
                        Player remotePlayer = lm.AddPlayer(ControllerType.Remote, remoteInfo.id, remoteInfo.name);
                        // 状态设置
                        RemotePlayerController rpc = remotePlayer.GetComponent <RemotePlayerController>();
                        rpc.ApplyRemoteInfo(remoteInfo);
                    }
                }

                initRecieved = true;
            }
        }
    }
예제 #2
0
 void OnRemotePlayerJoin(PlayerJoin join)
 {
     if (initRecieved)
     {
         PlayerInfo remoteInfo = join.info;
         if (remoteInfo != null)
         {
             Player remotePlayer        = lm.AddPlayer(ControllerType.Remote, remoteInfo.id, remoteInfo.name);
             RemotePlayerController rpc = remotePlayer.GetComponent <RemotePlayerController>();
             rpc.ApplyRemoteInfo(remoteInfo);
         }
     }
 }
예제 #3
0
 void OnUpdateGameInfo(ServerGameState state)
 {
     if (initRecieved)
     {
         foreach (PlayerInfo info in state.info)
         {
             Player player = lm.GetPlayer(info.id);
             if (player != null)
             {
                 if (player.playerType == PlayerType.Remote)
                 {
                     // 状态设置
                     RemotePlayerController rpc = player.GetComponent <RemotePlayerController>();
                     rpc.ApplyRemoteInfo(info);
                 }
             }
         }
     }
 }
예제 #4
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");
         }
     }
 }