mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkRoomManager - refactor CheckReadyToBegin
This commit is contained in:
parent
1e802c24c8
commit
324c41e1c7
@ -21,7 +21,7 @@ public class NetworkRoomManager : NetworkManager
|
||||
public struct PendingPlayer
|
||||
{
|
||||
public NetworkConnectionToClient conn;
|
||||
public GameObject roomPlayer;
|
||||
public GameObject roomPlayer;
|
||||
}
|
||||
|
||||
[Header("Room Settings")]
|
||||
@ -199,7 +199,12 @@ public void CheckReadyToBegin()
|
||||
if (!Utils.IsSceneActive(RoomScene))
|
||||
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;
|
||||
if (enoughReadyPlayers)
|
||||
{
|
||||
@ -207,9 +212,7 @@ public void CheckReadyToBegin()
|
||||
allPlayersReady = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
allPlayersReady = false;
|
||||
}
|
||||
}
|
||||
|
||||
internal void CallOnClientEnterRoom()
|
||||
@ -511,40 +514,40 @@ public override void OnClientSceneChanged()
|
||||
/// <summary>
|
||||
/// This is called on the host when a host is started.
|
||||
/// </summary>
|
||||
public virtual void OnRoomStartHost() {}
|
||||
public virtual void OnRoomStartHost() { }
|
||||
|
||||
/// <summary>
|
||||
/// This is called on the host when the host is stopped.
|
||||
/// </summary>
|
||||
public virtual void OnRoomStopHost() {}
|
||||
public virtual void OnRoomStopHost() { }
|
||||
|
||||
/// <summary>
|
||||
/// This is called on the server when the server is started - including when a host is started.
|
||||
/// </summary>
|
||||
public virtual void OnRoomStartServer() {}
|
||||
public virtual void OnRoomStartServer() { }
|
||||
|
||||
/// <summary>
|
||||
/// This is called on the server when the server is started - including when a host is stopped.
|
||||
/// </summary>
|
||||
public virtual void OnRoomStopServer() {}
|
||||
public virtual void OnRoomStopServer() { }
|
||||
|
||||
/// <summary>
|
||||
/// This is called on the server when a new client connects to the server.
|
||||
/// </summary>
|
||||
/// <param name="conn">The new connection.</param>
|
||||
public virtual void OnRoomServerConnect(NetworkConnectionToClient conn) {}
|
||||
public virtual void OnRoomServerConnect(NetworkConnectionToClient conn) { }
|
||||
|
||||
/// <summary>
|
||||
/// This is called on the server when a client disconnects.
|
||||
/// </summary>
|
||||
/// <param name="conn">The connection that disconnected.</param>
|
||||
public virtual void OnRoomServerDisconnect(NetworkConnectionToClient conn) {}
|
||||
public virtual void OnRoomServerDisconnect(NetworkConnectionToClient conn) { }
|
||||
|
||||
/// <summary>
|
||||
/// This is called on the server when a networked scene finishes loading.
|
||||
/// </summary>
|
||||
/// <param name="sceneName">Name of the new scene.</param>
|
||||
public virtual void OnRoomServerSceneChanged(string sceneName) {}
|
||||
public virtual void OnRoomServerSceneChanged(string sceneName) { }
|
||||
|
||||
/// <summary>
|
||||
/// This allows customization of the creation of the room-player object on the server.
|
||||
@ -608,7 +611,7 @@ public virtual void OnRoomServerPlayersReady()
|
||||
/// This is called on the server when CheckReadyToBegin finds that players are not ready
|
||||
/// <para>May be called multiple times while not ready players are joining</para>
|
||||
/// </summary>
|
||||
public virtual void OnRoomServerPlayersNotReady() {}
|
||||
public virtual void OnRoomServerPlayersNotReady() { }
|
||||
|
||||
#endregion
|
||||
|
||||
@ -617,37 +620,37 @@ public virtual void OnRoomServerPlayersNotReady() {}
|
||||
/// <summary>
|
||||
/// This is a hook to allow custom behaviour when the game client enters the room.
|
||||
/// </summary>
|
||||
public virtual void OnRoomClientEnter() {}
|
||||
public virtual void OnRoomClientEnter() { }
|
||||
|
||||
/// <summary>
|
||||
/// This is a hook to allow custom behaviour when the game client exits the room.
|
||||
/// </summary>
|
||||
public virtual void OnRoomClientExit() {}
|
||||
public virtual void OnRoomClientExit() { }
|
||||
|
||||
/// <summary>
|
||||
/// This is called on the client when it connects to server.
|
||||
/// </summary>
|
||||
public virtual void OnRoomClientConnect() {}
|
||||
public virtual void OnRoomClientConnect() { }
|
||||
|
||||
/// <summary>
|
||||
/// This is called on the client when disconnected from a server.
|
||||
/// </summary>
|
||||
public virtual void OnRoomClientDisconnect() {}
|
||||
public virtual void OnRoomClientDisconnect() { }
|
||||
|
||||
/// <summary>
|
||||
/// This is called on the client when a client is started.
|
||||
/// </summary>
|
||||
public virtual void OnRoomStartClient() {}
|
||||
public virtual void OnRoomStartClient() { }
|
||||
|
||||
/// <summary>
|
||||
/// This is called on the client when the client stops.
|
||||
/// </summary>
|
||||
public virtual void OnRoomStopClient() {}
|
||||
public virtual void OnRoomStopClient() { }
|
||||
|
||||
/// <summary>
|
||||
/// This is called on the client when the client is finished loading a new networked scene.
|
||||
/// </summary>
|
||||
public virtual void OnRoomClientSceneChanged() {}
|
||||
public virtual void OnRoomClientSceneChanged() { }
|
||||
|
||||
#endregion
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user