//Get the available color public Color ServerGetColor(MPNetworkPlayer player) { int playerIndex = _players.IndexOf(player); if (playerIndex == -1) { _players.Add(player); playerIndex = _players.Count - 1; } Color playerColor = player.Color; int index = _colors.IndexOf(playerColor); if (index == -1) { //Ensure that the first two tanks aren't both the same colours index = Random.Range(0, _colors.Count); while (index == _lastUsedColorIndex) { index = Random.Range(0, _colors.Count); } _lastUsedColorIndex = index; } else { index++; } if (index == _colors.Count) { index = 0; } Color newColor = _colors[index]; if (CanUseColor(newColor, playerIndex)) { return(newColor); } return(playerColor); }
public void Init(MPNetworkPlayer player) { Debug.LogFormat("Initializing lobby player - Ready {0}", player.Ready); this._mpNetworkPlayer = player; if (player != null) { player.SyncVarsChanged += OnNetworkPlayerSyncvarChanged; } _netManager = MPNetworkManager.singleton.gameObject.GetComponent <MPNetworkManager>(); //TanksNetworkManager.s_Instance; if (_netManager != null) { _netManager.playerJoined += PlayerJoined; _netManager.playerLeft += PlayerLeft; } _readyLabel.gameObject.SetActive(false); _waitingLabel.gameObject.SetActive(false); _readyButton.gameObject.SetActive(true); _readyButton.interactable = _netManager.hasSufficientPlayers; if (_netManager.gameType == NetworkGameType.SinglePlayer) { return; } MainMenuUI mainMenu = MainMenuUI.Instance; mainMenu.playerList.AddPlayer(this); mainMenu.playerList.DisplayDirectServerWarning(player.isServer && _netManager.matchMaker == null); if (player.hasAuthority) { SetupLocalPlayer(); } else { SetupRemotePlayer(); } UpdateValues(); }
private void OnNetworkPlayerSyncvarChanged(MPNetworkPlayer player) { // Update everything UpdateValues(); }
protected virtual void PlayerLeft(MPNetworkPlayer player) { RefreshJoinButton(); }
//Log player leaving for tracing protected virtual void PlayerLeft(MPNetworkPlayer player) { Debug.LogFormat("Player left {0}", player.name); }
//Log player joining for tracing protected virtual void PlayerJoined(MPNetworkPlayer player) { Debug.LogFormat("Player joined {0}", player.name); }