// create first local/remote client void CreatePlayer(NetworkConnection conn) { ClientScene.Ready(conn); var extraMessage = new CustomAddPlayerMessage(userManager.GetActiveUser()); ClientScene.AddPlayer(null, 0, extraMessage); // TODO remove this!!! if (sceneToggle.isOn) { ClientScene.AddPlayer(null, 1, extraMessage); } }
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId, NetworkReader messageReader) { if (state != DNMState.Host) { Log.Warn("Unexpected call of OnServerAddPlayer"); return; } CustomAddPlayerMessage msg = messageReader.ReadMessage <CustomAddPlayerMessage>(); string username = msg.username; var player = GameObject.Instantiate(onlinePlayerModel /*, playerContainer not needed */) as OnlinePlayer; UserProfile user = new UserProfile(username); int role = DNM.SpecRole; if (gameState == GameState.NoGame) { int nextRole = GetNextRole(); role = nextRole; } else if (gameState == GameState.WillStart || gameState == GameState.Playing || gameState == GameState.GameOver) { role = DNM.SpecRole; } else { Log.Warn("Unexpected gameState {0}", gameState); } player.SetUser(user); player.SetRole(role); GetClient(conn).AddPlayer(player); NetworkServer.AddPlayerForConnection(conn, player.gameObject, playerControllerId); }