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 struct PendingPlayer
|
||||||
{
|
{
|
||||||
public NetworkConnectionToClient conn;
|
public NetworkConnectionToClient conn;
|
||||||
public GameObject roomPlayer;
|
public GameObject roomPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Header("Room Settings")]
|
[Header("Room Settings")]
|
||||||
@ -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,9 +212,7 @@ public void CheckReadyToBegin()
|
|||||||
allPlayersReady = true;
|
allPlayersReady = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
allPlayersReady = false;
|
allPlayersReady = false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void CallOnClientEnterRoom()
|
internal void CallOnClientEnterRoom()
|
||||||
@ -511,40 +514,40 @@ public override void OnClientSceneChanged()
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called on the host when a host is started.
|
/// This is called on the host when a host is started.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void OnRoomStartHost() {}
|
public virtual void OnRoomStartHost() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called on the host when the host is stopped.
|
/// This is called on the host when the host is stopped.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void OnRoomStopHost() {}
|
public virtual void OnRoomStopHost() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called on the server when the server is started - including when a host is started.
|
/// This is called on the server when the server is started - including when a host is started.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void OnRoomStartServer() {}
|
public virtual void OnRoomStartServer() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called on the server when the server is started - including when a host is stopped.
|
/// This is called on the server when the server is started - including when a host is stopped.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void OnRoomStopServer() {}
|
public virtual void OnRoomStopServer() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called on the server when a new client connects to the server.
|
/// This is called on the server when a new client connects to the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="conn">The new connection.</param>
|
/// <param name="conn">The new connection.</param>
|
||||||
public virtual void OnRoomServerConnect(NetworkConnectionToClient conn) {}
|
public virtual void OnRoomServerConnect(NetworkConnectionToClient conn) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called on the server when a client disconnects.
|
/// This is called on the server when a client disconnects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="conn">The connection that disconnected.</param>
|
/// <param name="conn">The connection that disconnected.</param>
|
||||||
public virtual void OnRoomServerDisconnect(NetworkConnectionToClient conn) {}
|
public virtual void OnRoomServerDisconnect(NetworkConnectionToClient conn) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called on the server when a networked scene finishes loading.
|
/// This is called on the server when a networked scene finishes loading.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sceneName">Name of the new scene.</param>
|
/// <param name="sceneName">Name of the new scene.</param>
|
||||||
public virtual void OnRoomServerSceneChanged(string sceneName) {}
|
public virtual void OnRoomServerSceneChanged(string sceneName) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This allows customization of the creation of the room-player object on the server.
|
/// 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
|
/// 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>
|
/// <para>May be called multiple times while not ready players are joining</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void OnRoomServerPlayersNotReady() {}
|
public virtual void OnRoomServerPlayersNotReady() { }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -617,37 +620,37 @@ public virtual void OnRoomServerPlayersNotReady() {}
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is a hook to allow custom behaviour when the game client enters the room.
|
/// This is a hook to allow custom behaviour when the game client enters the room.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void OnRoomClientEnter() {}
|
public virtual void OnRoomClientEnter() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is a hook to allow custom behaviour when the game client exits the room.
|
/// This is a hook to allow custom behaviour when the game client exits the room.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void OnRoomClientExit() {}
|
public virtual void OnRoomClientExit() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called on the client when it connects to server.
|
/// This is called on the client when it connects to server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void OnRoomClientConnect() {}
|
public virtual void OnRoomClientConnect() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called on the client when disconnected from a server.
|
/// This is called on the client when disconnected from a server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void OnRoomClientDisconnect() {}
|
public virtual void OnRoomClientDisconnect() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called on the client when a client is started.
|
/// This is called on the client when a client is started.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void OnRoomStartClient() {}
|
public virtual void OnRoomStartClient() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called on the client when the client stops.
|
/// This is called on the client when the client stops.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void OnRoomStopClient() {}
|
public virtual void OnRoomStopClient() { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is called on the client when the client is finished loading a new networked scene.
|
/// This is called on the client when the client is finished loading a new networked scene.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void OnRoomClientSceneChanged() {}
|
public virtual void OnRoomClientSceneChanged() { }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user