本文整理汇总了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);
}
示例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;
}
示例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");
//.........这里部分代码省略.........