Fixed Lobby Text Not Updating After First Round

This commit is contained in:
2021-12-10 15:14:16 -06:00
parent 45ce1576b5
commit a9a19cb56a
5 changed files with 58 additions and 31 deletions

View File

@@ -21,6 +21,8 @@ public class LobbyUI : NetworkBehaviour {
private NetworkList<LobbyPlayerState> lobbyPlayers = new NetworkList<LobbyPlayerState>();
private NetworkVariable<String> hostIpAddress = new NetworkVariable<String>();
private string LobbyStatusText = "";
public override void NetworkStart()
{
// Unlock the player cursor if they get sent back here after a match
@@ -45,6 +47,8 @@ public class LobbyUI : NetworkBehaviour {
// Get/Set the ip of the host
StartCoroutine(GetIPAddress());
UpdateLobbyStateText();
}
// Reset the variables for IsReady and IsKing
@@ -70,6 +74,11 @@ public class LobbyUI : NetworkBehaviour {
}
}
void Start() {
ToggleReadyServerRpc();
ToggleReadyServerRpc();
}
private void OnDestroy()
{
lobbyPlayers.OnListChanged -= HandleLobbyPlayersStateChanged;
@@ -261,13 +270,18 @@ public class LobbyUI : NetworkBehaviour {
}
}
UpdateLobbyStateText();
if (IsServer) {
UpdateLobbyStateText();
}
}
private void UpdateLobbyStateText() {
if (lobbyPlayers.Count != 3) {
lobbyStateText.text = "Need 3 Players to Begin!";
LobbyStatusText = "Need 3 Players to Begin!";
if (IsServer) {
UpdateLobbyStateTextServerRPC(LobbyStatusText);
}
return;
}
@@ -286,15 +300,33 @@ public class LobbyUI : NetworkBehaviour {
// Verify counts
if (runnerCount != 2 || kingCount != 1) {
lobbyStateText.text = "Need 2 Runners and 1 King!";
LobbyStatusText = "Need 2 Runners and 1 King!";
if (IsServer) {
UpdateLobbyStateTextServerRPC(LobbyStatusText);
}
return;
}
lobbyStateText.text = "All Players Ready!";
LobbyStatusText = "All Players Ready!";
}
else {
lobbyStateText.text = "All Players Need to Ready Up!";
LobbyStatusText = "All Players Need to Ready Up!";
}
if (IsServer) {
UpdateLobbyStateTextServerRPC(LobbyStatusText);
}
}
[ServerRpc(RequireOwnership = false)]
private void UpdateLobbyStateTextServerRPC(string stateText) {
LobbyStatusText = stateText;
UpdateLobbyStateTextClientRPC(stateText);
}
[ClientRpc]
private void UpdateLobbyStateTextClientRPC(string stateText) {
LobbyStatusText = stateText;
}
//Taken from Goodgulf
@@ -322,5 +354,6 @@ public class LobbyUI : NetworkBehaviour {
void Update() {
hostIpAddressText.text = hostIpAddress.Value;
lobbyStateText.text = LobbyStatusText;
}
}

View File

@@ -11,21 +11,15 @@ public class PostGameUI : NetworkBehaviour {
[SerializeField] private int ReturnToLobbyTimer;
[SerializeField] private TMP_Text HeaderText;
private string TEXT;
void Start() {
ReturnToLobbyText.text = "Returning to the lobby in " + ReturnToLobbyTimer + " seconds...";
StartCoroutine(BeginCountdown());
//todo: do logic to determine and update who won the round
UpdateWinnerTextServerRPC();
}
void Update() {
HeaderText.text = TEXT;
}
[ServerRpc]
[ServerRpc(RequireOwnership = false)]
private void UpdateWinnerTextServerRPC() {
List<string> playerFinishedNames = new List<string>();
string kingName = "";
@@ -65,7 +59,7 @@ public class PostGameUI : NetworkBehaviour {
[ClientRpc]
private void UpdateWinnerTextClientRPC(string winnerText) {
TEXT = winnerText;
HeaderText.text = winnerText;
}
IEnumerator BeginCountdown() {