public override void OnRoomServerDisconnect(NetworkConnection conn) { Debug.Log($"Client has disconnected with {conn.connectionId}"); if (SceneManager.GetActiveScene().name == "RoomScene") { ClientOnDisconnected?.Invoke(conn); PlayerReadyBar readyBar = null; GameObject readyBarParent = null; int i = 1; // Loop until fetching a free ready bar while (i <= 10) { string nodeName = $"/PlayerBoxes/Panel/Player ({i})"; readyBarParent = GameObject.Find(nodeName); readyBar = readyBarParent.GetComponentInChildren <PlayerReadyBar>(true); Debug.Log($"Trying {nodeName} to see if free"); int currentClientId = readyBar.GetPlayerId(); if (currentClientId == conn.connectionId) { Debug.Log("Setting ready bar to deactive"); readyBar.ServerToggleParentActive(false); Debug.Log($"Setting {nodeName} to -1"); readyBar.SetPlayerId(-1); break; } i++; } } base.OnRoomServerDisconnect(conn); }
public override void OnServerAddPlayer(NetworkConnection conn) { base.OnServerAddPlayer(conn); Debug.Log("Server Add Player"); Debug.Log($"Connection is {conn.connectionId}"); ClientOnConnected?.Invoke(conn); PlayerReadyBar readyBar = null; GameObject readyBarParent = null; int i = 1; // Loop until fetching a free ready bar slot while (i <= 10) { string nodeName = $"/PlayerBoxes/Panel/Player ({i})"; readyBarParent = GameObject.Find(nodeName); Debug.Log($"Finding node {nodeName}: {readyBarParent}"); Debug.Log($"Children are {readyBarParent.transform.GetChild(0)}"); readyBar = readyBarParent.GetComponentInChildren <PlayerReadyBar>(true); Debug.Log("Setting ready bar to active"); readyBar.ServerToggleParentActive(true); Debug.Log($"Trying {nodeName} to see if free, id is {readyBar.GetPlayerId()}"); int currentClientId = readyBar.GetPlayerId(); if (currentClientId == -1) { Debug.Log($"Setting {nodeName} to player {conn.connectionId}"); readyBar.SetPlayerId(conn.connectionId); break; } i++; } }
public void ReadyStateChanged(NetworkConnection conn) { base.OnServerReady(conn); PlayerReadyBar readyBar = null; GameObject readyBarParent = null; int i = 1; while (i <= 10) { string nodeName = $"/PlayerBoxes/Panel/Player ({i})"; readyBarParent = GameObject.Find(nodeName); Debug.Log($"Fetching ready bar object from {readyBarParent}"); readyBar = readyBarParent.GetComponentInChildren <PlayerReadyBar>(true); Debug.Log($"Trying {nodeName} to see if free"); int currentClientId = readyBar.GetPlayerId(); if (currentClientId == conn.connectionId) { Debug.Log("Calling RpcToggleReady"); readyBar.ServerToggleIsReady(); // If not ready then make sure the start button is disabled break; } i++; } }