当前位置: 首页>>代码示例>>C#>>正文


C# NetworkReader.ReadMessage方法代码示例

本文整理汇总了C#中NetworkReader.ReadMessage方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkReader.ReadMessage方法的具体用法?C# NetworkReader.ReadMessage怎么用?C# NetworkReader.ReadMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetworkReader的用法示例。


在下文中一共展示了NetworkReader.ReadMessage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnServerAddPlayer

        /// <summary>
        /// Called on the server when a new client connects and is requesting to be spawned as a player object.
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="playerControllerId"></param>
        /// <param name="netMsg"></param>
        public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId, NetworkReader netMsg)
        {
            //base.OnServerAddPlayer(conn, playerControllerId, netMsg);

            var msg = netMsg.ReadMessage<AddPlayerMessage>();
            Debug.Log("Adding player... " + msg.name + " " + playerPrefabs[msg.playerPrefabIndex].name);
            GameObject player = (GameObject)Instantiate(playerPrefabs[msg.playerPrefabIndex], Vector3.zero, Quaternion.identity);

            var gamePlayer = player.GetComponent<GamePlayer>();
            gamePlayer.displayName = msg.name;

            NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
        }
开发者ID:cpvrlab,项目名称:VirtualTable,代码行数:19,代码来源:VTNetworkManager.cs

示例2: OnServerAddPlayer

 public override void OnServerAddPlayer(NetworkConnection connection, short playerControllerId, NetworkReader extraMessageReader)
 {
     string username = extraMessageReader.ReadMessage<UsernameMsg>().username;
     if (Network.connections.Length <= MaxConnections && !GameObject.Find("Game").GetComponent<ServerLogic>().GameStarted)
     {
         // Instantiate a Player
         GameObject player = (GameObject)GameObject.Instantiate(playerPrefab, GetStartPosition().position, Quaternion.identity);
         player.GetComponent<PlayerState>().username = username;
         NetworkServer.AddPlayerForConnection(connection, player, playerControllerId);
         player.GetComponent<PlayerState>().CmdBroadcastNotification(username + " connected to the game!");
     }
     else
         // [Todo] Handle players disconnecting, and reconnecting later.
         Network.maxConnections = 0;
 }
开发者ID:BastiaanGrisel,项目名称:PrivacyAwarenessGame,代码行数:15,代码来源:NetworkManager.cs

示例3: OnServerAddPlayer

    public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId, NetworkReader extraMessageReader)
    {
        Debug.Log("OnServerAddPlayer " + conn.connectionId);
        //cannot add base.OnServerAddPlayer(conn, playerControllerId);
        string playerName = "";
        if (extraMessageReader != null)
        {
            var s = extraMessageReader.ReadMessage<PlayerMessage>();
            playerName = s.userName;
            Debug.Log("my name is " + s.userName);
        }
        switch (currentMode)
        {
            case NetworkMode.Level: 
            case NetworkMode.Lobby:
                Debug.Log("OnServerAddPlayer Lobby ");
                //find out the name does not exist
                if(!CheckUserNameValid(playerName)){
                    ErrorMessage em = new ErrorMessage();
                    em.errorMessage = "This Account Has Already Connected to Server.";
                    NetworkServer.SendToClient(conn.connectionId, ErrorMessage.MsgType, em);
                    return;
                }
                //find a empty slot
                int i = 0;
                for (; i < maxPlayers; i++)
                    if (lobbyPlayerArray[i] == null) break;
                if (i == maxPlayers) return;
                //create lobby object
                var player = (GameObject)GameObject.Instantiate(LobbyPlayerPrefab, Vector3.zero, Quaternion.identity);
                player.GetComponent<LobbyPlayer>().slot = i;
                player.GetComponent<LobbyPlayer>().ownRole = PlayerRole.Unselected;

                //player.GetComponent<LobbyPlayer>().currentMode = currentMode;

                Debug.Log("OnServerAddPlayer Lobby ");

                lobbyPlayerArray[i] = player.GetComponent<LobbyPlayer>();

                //player.GetComponent<LobbyPlayer>().ToggleVisibility(false);
                NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
                if(currentMode == NetworkMode.Lobby)
                { // make lobby visible amoung all clients and server
                    ChangeVisibilityOfLobbyPlayerEverywhere(true);
                }
                break;
            case NetworkMode.Game:
                Debug.Log("OnServerAddPlayer Game ");
                bool isExistingPlayer = false;
                for (int k = 0; k < maxPlayers; k++)
                {
                    if (disconnectedPlayerControllers[k] != null)
                    {
                        DisconnectedPlayerController dpc = (DisconnectedPlayerController)disconnectedPlayerControllers[k];
                        int dpcconnid = dpc.connId;
                        // Disconnected player to Game Player
                        if (dpc.username == playerName)
                        {
                            //TODO: Disconnect to Player
                            isExistingPlayer = true;
                            Debug.Log(k + " existing " + dpcconnid);
                            disconnectedPlayerControllers[k] = null;

                            GameObject selectedprefab = StrikerPrefab;
                            switch (dpc.currentRole)
                            {
                                case PlayerRole.Engineer:
                                    selectedprefab = EngineerPrefab;
                                    Debug.Log("Reconnect EngineerPrefab");
                                    break;
                            }

                            GameObject gamePlayer = (GameObject)Instantiate(selectedprefab, Vector3.zero, Quaternion.identity);
                            gameplayerControllers[k] = gamePlayer.GetComponent<PlayerController>();
                            PlayerController pc = gamePlayer.GetComponent<PlayerController>();
                            pc.slot = k;
                            pc.username = dpc.username;
                            pc.role = dpc.currentRole;
                            pc.rank = dpc.rank;
                            pc.exp = dpc.exp;
                            pc.score = dpc.score;
                            pc.skill1Counter = dpc.skill1Counter;
                            pc.skill2Counter = dpc.skill2Counter;
                            pc.supportCounter = dpc.supportCounter;
                            pc.setInGame();
                            pc.disconnectCrystal = dpc.crystals;
                            pc.InitializeDisconnectCrystals(dpc.crystals);
                            pc.isPause = dpc.isPause;

                            if (dpc.currentRole == PlayerRole.Engineer)
                            {
                                SetUpEngineerTeammateInfo(gamePlayer.GetComponent<EngineerController>());
                                pc.GetComponent<EngineerController>().initializeData();
                            }
                            else
                            {
                                pc.GetComponent<PlayerController>().initializeData();
                            }

                            Debug.Log("Network Manager InitializeData");
//.........这里部分代码省略.........
开发者ID:charmjunewonder,项目名称:RiverRun,代码行数:101,代码来源:NetworkManagerCustom.cs


注:本文中的NetworkReader.ReadMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。