NetworkRoomManager - refactor CheckReadyToBegin

This commit is contained in:
MrGadget1024 2023-02-08 10:04:30 -05:00
parent 1e802c24c8
commit 324c41e1c7

View File

@ -199,7 +199,12 @@ public void CheckReadyToBegin()
if (!Utils.IsSceneActive(RoomScene)) if (!Utils.IsSceneActive(RoomScene))
return; return;
int numberOfReadyPlayers = NetworkServer.connections.Count(conn => conn.Value != null && conn.Value.identity.gameObject.GetComponent<NetworkRoomPlayer>().readyToBegin); int numberOfReadyPlayers = NetworkServer.connections.Count(conn =>
conn.Value != null &&
conn.Value.identity != null &&
conn.Value.identity.TryGetComponent(out NetworkRoomPlayer nrp) &&
nrp.readyToBegin);
bool enoughReadyPlayers = minPlayers <= 0 || numberOfReadyPlayers >= minPlayers; bool enoughReadyPlayers = minPlayers <= 0 || numberOfReadyPlayers >= minPlayers;
if (enoughReadyPlayers) if (enoughReadyPlayers)
{ {
@ -207,10 +212,8 @@ public void CheckReadyToBegin()
allPlayersReady = true; allPlayersReady = true;
} }
else else
{
allPlayersReady = false; allPlayersReady = false;
} }
}
internal void CallOnClientEnterRoom() internal void CallOnClientEnterRoom()
{ {