private void Rpc_disconnect() { //GameObject.Find ("Custom Network Manager").GetComponent<CustomNetworkManager>().client.connection.Disconnect(); Destroy(GameObject.Find("Custom Network Manager")); ClientScene.RemovePlayer(0); ClientScene.readyConnection.Disconnect(); }
void Update() { #if PUN_2_OR_NEWER #elif MIRROR if (Input.GetKeyDown(join)) { ClientScene.AddPlayer(); } if (Input.GetKeyDown(leave)) { ClientScene.RemovePlayer(); } #else if (Input.GetKeyDown(join)) { ClientScene.AddPlayer(0); } if (Input.GetKeyDown(leave)) { ClientScene.RemovePlayer(0); } #endif }
public void UnloadNetwork() { if (Solo == false) { Debug.Log("Remove Player : " + ClientScene.RemovePlayer(1)); networkManager.Disconnect(); } }
public override void OnStopClient() { Debug.Log("OnStopClient: " + _playerControllerId); ClientScene.RemovePlayer(_playerControllerId); CP_GameManager.Instance.NetworkGameState.NumPlayers--; base.OnStopClient(); }
/// <summary> /// Removes the player and updates buttons' interactivity. /// </summary> /// <param name="playerControllerId">ID of the player controller the player is using</param> public void RemovePlayer(short playerControllerId) { ClientScene.RemovePlayer(playerControllerId); if (lobbyManager.playerCount == 1 && playButton != null) { playButton.interactable = false; } if (lobbyManager.maxPlayers - 1 == lobbyManager.playerCount && addPlayerbutton != null) { addPlayerbutton.interactable = true; } }
public void RemovePlayer() { if (isLocalPlayer && !m_ReadyToBegin) { if (LogFilter.logDebug) { Debug.Log("NetworkLobbyPlayer RemovePlayer"); } ClientScene.RemovePlayer(GetComponent <NetworkIdentity>().playerControllerId); } }
public override void OnClientDisconnect(NetworkConnection conn) { Debug.Log("OnClientDisconnect: " + _playerControllerId); ClientScene.RemovePlayer((short)conn.connectionId); if (!_localClientRemoved && conn.connectionId == _playerControllerId) { _localClientRemoved = true; } base.OnClientDisconnect(conn); }
public void PlayerDie() { MainGUI.Current.DeathScreen.SetActive(true); MainGUI.Current.GameGUI.SetActive(false); SetTimeOut(() => { ClientScene.RemovePlayer(0); var teamid = PlayerObject.GetComponent <Player>().TeamID; PlayerObject.GetComponent <Player>().CmdDestroy(); NetworkSystem.Current.JoinTeam(teamid); MainGUI.Current.DeathScreen.SetActive(false); }, 3); }
void OnGUIRemove() { if (isLocalPlayer) { ClientScene.RemovePlayer(lobbyPlayer.playerControllerId); var lobby = NetworkManager.singleton as GuiLobbyManager; if (lobby != null) { lobby.SetFocusToAddPlayerButton(); } } }
public override void OnStopClient() { Debug.Log("OnStopClient: " + _playerControllerId); if (!_localClientRemoved) { ClientScene.RemovePlayer(_playerControllerId); } _localClientRemoved = true; GSB_GameManager.Instance.NetworkGameState.NumPlayers--; base.OnStopClient(); }
public override void OnNetworkDestroy() { base.OnNetworkDestroy(); if (isClient) { Camera cam = Camera.main; if (cam.transform.parent == this.transform) { cam.transform.parent = null; } showUiGame(false); ClientScene.RemovePlayer(0); } else { //ClientScene.AddPlayer(0); } }
public void Update() { if (client == null) { return; } for (int player = 0; player < Input.GetJoystickNames().Length; player++) { bool hasObject = ClientScene.localPlayers.Where(x => x.playerControllerId == player).FirstOrDefault() != null; if (player.GetButtonDown("R_SELECT")) { if (!hasObject) { ClientScene.AddPlayer(client.connection, (short)player); } playerLastPressed.Add(player, Time.time); } if (!player.GetButton("R_SELECT") && playerLastPressed.ContainsKey(player)) { playerLastPressed.Remove(player); } if (playerLastPressed.ContainsKey(player) && playerLastPressed[player] + 1 <= Time.time) { if (hasObject) { ClientScene.RemovePlayer((short)player); } playerLastPressed.Remove(player); } } }
public override void OnEnter() { base.OnEnter(); ClientScene.RemovePlayer((short)playerId.Value); Finish(); }
void AddPlayer(NetworkConnection conn, short playerControllerId, PlayerSelection selection) { if (playerControllerId < conn.playerControllers.Count && conn.playerControllers[playerControllerId].IsValid && conn.playerControllers[playerControllerId].gameObject != null) { Log.Error("There is already a player at that playerControllerId for this connections."); return; } var startPosition = GetStartPosition(); var character = selection.Character; bool random = character == null; Analytics.CustomEvent("characterSelected", new Dictionary <string, object> { { "character", character != null ? character.name : "Random" }, { "color", selection.Pallete }, }); if (random) { Log.Info("No character was specfied, randomly selecting character and pallete..."); selection.Character = DataManager.Characters.Random(); selection.Pallete = Mathf.FloorToInt(Random.value * selection.Character.PalleteCount); } var sameCharacterSelections = new HashSet <PlayerSelection>(PlayerManager.MatchPlayers.Select(p => p.Selection)); if (sameCharacterSelections.Contains(selection)) { bool success = false; for (var i = 0; i < selection.Character.PalleteCount; i++) { selection.Pallete = i; if (!sameCharacterSelections.Contains(selection)) { success = true; break; } } if (!success) { Log.Error("Two players made the same selection, and no remaining palletes remain. {0} doesn't have enough colors".With(selection.Character)); ClientScene.RemovePlayer(playerControllerId); return; } } selection.Character.Prefab.LoadAsync().Then(prefab => { if (prefab == null) { Log.Error("The character {0} does not have a prefab. Please add a prefab object to it.", selection.Character); return; } if (prefab.GetComponent <NetworkIdentity>() == null) { Log.Error( "The character prefab for {0} does not have a NetworkIdentity. Please add a NetworkIdentity to it's prefab.", selection.Character); return; } GameObject playerObj; if (startPosition != null) { playerObj = Instantiate(prefab, startPosition.position, startPosition.rotation); } else { playerObj = Instantiate(prefab, Vector3.zero, Quaternion.identity); } var player = PlayerManager.MatchPlayers.Get(playerCount); playerObj.name = "Player {0} ({1},{2})".With(playerCount + 1, selection.Character.name, selection.Pallete); NetworkServer.AddPlayerForConnection(conn, playerObj, playerControllerId); var colorState = playerObj.GetComponentInChildren <ColorState>(); if (colorState != null) { colorState.Pallete = selection.Pallete; } player.Selection = selection; player.Type = PlayerType.HumanPlayer; player.PlayerObject = playerObj; playerCount++; NetworkServer.SendToAll(Messages.UpdatePlayer, UpdatePlayerMessage.FromPlayer(player)); var playerConnection = new PlayerConnection { ConnectionID = conn.connectionId, PlayerControllerID = playerControllerId }; PlayerMap[playerConnection] = player; playerObj.GetComponentsInChildren <IDataComponent <Player> >().SetData(player); //player.Changed += () => playerObj.GetComponentInChildren<IDataComponent<Player>>().SetData(player); }); }
// Shows GUI in lobby scene for each lobby player void OnGUI() { if (!ShowLobbyGUI) { return; } var lobby = NetworkManager.singleton as NetworkLobbyManager; if (lobby) { if (!lobby.showLobbyGUI) { return; } string loadedSceneName = SceneManager.GetSceneAt(0).name; if (loadedSceneName != lobby.lobbyScene) { return; } } Rect rec = new Rect(100 + slot * 100, 200, 90, 20); if (isLocalPlayer) { string youStr; if (readyToBegin) { youStr = "(Ready)"; } else { youStr = "(Not Ready)"; } GUI.Label(rec, youStr); if (readyToBegin) { rec.y += 25; if (GUI.Button(rec, "STOP")) { SendNotReadyToBeginMessage(); } } else { rec.y += 25; if (GUI.Button(rec, "START")) { SendReadyToBeginMessage(); } rec.y += 25; if (GUI.Button(rec, "Remove")) { ClientScene.RemovePlayer(GetComponent <NetworkIdentity>().playerControllerId); } rec.y += 25; if (!seeker) { if (GUI.Button(rec, "Hider")) { CmdSetSeeker(true); } } else { if (GUI.Button(rec, "Seeker")) { CmdSetSeeker(false); } } } } else { GUI.Label(rec, "Player [" + netId + "]"); rec.y += 25; GUI.Label(rec, "Ready [" + readyToBegin + "]"); } }
void RpcRestart() { ClientScene.RemovePlayer(playerId); ClientScene.AddPlayer(playerId); }
public void CmdNetworkDestroy() { ClientScene.RemovePlayer(playerControllerId); NetworkServer.Destroy(this.gameObject); }
public void RemoveButton() { ClientScene.RemovePlayer(GetComponent <NetworkIdentity>().playerControllerId); }