From 94330010c73fce6d8ae5b2237bf8cba90e2a78eb Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Sun, 19 May 2024 07:53:33 -0400 Subject: [PATCH] fix(NetworkRoomManager): Hashset instead of List --- .../Mirror/Components/NetworkRoomManager.cs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Assets/Mirror/Components/NetworkRoomManager.cs b/Assets/Mirror/Components/NetworkRoomManager.cs index 11e17f2cc7f..4df69c6fa63 100644 --- a/Assets/Mirror/Components/NetworkRoomManager.cs +++ b/Assets/Mirror/Components/NetworkRoomManager.cs @@ -56,7 +56,7 @@ public struct PendingPlayer /// List of players that are in the Room /// [FormerlySerializedAs("m_PendingPlayers")] - public List pendingPlayers = new List(); + public HashSet pendingPlayers = new HashSet(); [Header("Diagnostics")] /// @@ -71,7 +71,7 @@ public struct PendingPlayer /// The slotId on players is global to the game - across all players. /// [ReadOnly, Tooltip("List of Room Player objects")] - public List roomSlots = new List(); + public HashSet roomSlots = new HashSet(); public bool allPlayersReady { @@ -251,11 +251,10 @@ public override void OnServerDisconnect(NetworkConnectionToClient conn) OnRoomServerDisconnect(conn); base.OnServerDisconnect(conn); - if (Utils.IsHeadless()) - { - if (numPlayers < 1) - StopServer(); - } + // Restart the server if we're headless and no players are connected. + // This will send server to offline scene, where auto-start will run. + if (Utils.IsHeadless() && numPlayers < 1) + StopServer(); } // Sequential index used in round-robin deployment of players into instances and score positioning @@ -316,10 +315,9 @@ public void RecalculateRoomPlayerIndices() { if (roomSlots.Count > 0) { - for (int i = 0; i < roomSlots.Count; i++) - { - roomSlots[i].index = i; - } + int i = 0; + foreach (NetworkRoomPlayer player in roomSlots) + player.index = i++; } }