mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix: NetworkRoomManager.ReadyStatusChange is now a virtual method
- Script Template updated accordingly. Fixes #1889
This commit is contained in:
parent
e260d1eb2a
commit
80211ba827
@ -118,47 +118,6 @@ public override void OnValidate()
|
||||
}
|
||||
}
|
||||
|
||||
public void ReadyStatusChanged()
|
||||
{
|
||||
int CurrentPlayers = 0;
|
||||
int ReadyPlayers = 0;
|
||||
|
||||
foreach (NetworkRoomPlayer item in roomSlots)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
CurrentPlayers++;
|
||||
if (item.readyToBegin)
|
||||
ReadyPlayers++;
|
||||
}
|
||||
}
|
||||
|
||||
if (CurrentPlayers == ReadyPlayers)
|
||||
CheckReadyToBegin();
|
||||
else
|
||||
allPlayersReady = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on the server when a client is ready.
|
||||
/// <para>The default implementation of this function calls NetworkServer.SetClientReady() to continue the network setup process.</para>
|
||||
/// </summary>
|
||||
/// <param name="conn">Connection from client.</param>
|
||||
public override void OnServerReady(NetworkConnectionToClient conn)
|
||||
{
|
||||
Debug.Log($"NetworkRoomManager OnServerReady {conn}");
|
||||
base.OnServerReady(conn);
|
||||
|
||||
if (conn != null && conn.identity != null)
|
||||
{
|
||||
GameObject roomPlayer = conn.identity.gameObject;
|
||||
|
||||
// if null or not a room player, don't replace it
|
||||
if (roomPlayer != null && roomPlayer.GetComponent<NetworkRoomPlayer>() != null)
|
||||
SceneLoadedForPlayer(conn, roomPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
void SceneLoadedForPlayer(NetworkConnectionToClient conn, GameObject roomPlayer)
|
||||
{
|
||||
Debug.Log($"NetworkRoom SceneLoadedForPlayer scene: {SceneManager.GetActiveScene().path} {conn}");
|
||||
@ -190,6 +149,26 @@ void SceneLoadedForPlayer(NetworkConnectionToClient conn, GameObject roomPlayer)
|
||||
NetworkServer.ReplacePlayerForConnection(conn, gamePlayer, true);
|
||||
}
|
||||
|
||||
internal void CallOnClientEnterRoom()
|
||||
{
|
||||
OnRoomClientEnter();
|
||||
foreach (NetworkRoomPlayer player in roomSlots)
|
||||
if (player != null)
|
||||
{
|
||||
player.OnClientEnterRoom();
|
||||
}
|
||||
}
|
||||
|
||||
internal void CallOnClientExitRoom()
|
||||
{
|
||||
OnRoomClientExit();
|
||||
foreach (NetworkRoomPlayer player in roomSlots)
|
||||
if (player != null)
|
||||
{
|
||||
player.OnClientExitRoom();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CheckReadyToBegin checks all of the players in the room to see if their readyToBegin flag is set.
|
||||
/// <para>If all of the players are ready, then the server switches from the RoomScene to the PlayScene, essentially starting the game. This is called automatically in response to NetworkRoomPlayer.CmdChangeReadyState.</para>
|
||||
@ -215,26 +194,6 @@ public void CheckReadyToBegin()
|
||||
allPlayersReady = false;
|
||||
}
|
||||
|
||||
internal void CallOnClientEnterRoom()
|
||||
{
|
||||
OnRoomClientEnter();
|
||||
foreach (NetworkRoomPlayer player in roomSlots)
|
||||
if (player != null)
|
||||
{
|
||||
player.OnClientEnterRoom();
|
||||
}
|
||||
}
|
||||
|
||||
internal void CallOnClientExitRoom()
|
||||
{
|
||||
OnRoomClientExit();
|
||||
foreach (NetworkRoomPlayer player in roomSlots)
|
||||
if (player != null)
|
||||
{
|
||||
player.OnClientExitRoom();
|
||||
}
|
||||
}
|
||||
|
||||
#region server handlers
|
||||
|
||||
/// <summary>
|
||||
@ -301,6 +260,26 @@ public override void OnServerDisconnect(NetworkConnectionToClient conn)
|
||||
// Sequential index used in round-robin deployment of players into instances and score positioning
|
||||
public int clientIndex;
|
||||
|
||||
/// <summary>
|
||||
/// Called on the server when a client is ready.
|
||||
/// <para>The default implementation of this function calls NetworkServer.SetClientReady() to continue the network setup process.</para>
|
||||
/// </summary>
|
||||
/// <param name="conn">Connection from client.</param>
|
||||
public override void OnServerReady(NetworkConnectionToClient conn)
|
||||
{
|
||||
Debug.Log($"NetworkRoomManager OnServerReady {conn}");
|
||||
base.OnServerReady(conn);
|
||||
|
||||
if (conn != null && conn.identity != null)
|
||||
{
|
||||
GameObject roomPlayer = conn.identity.gameObject;
|
||||
|
||||
// if null or not a room player, don't replace it
|
||||
if (roomPlayer != null && roomPlayer.GetComponent<NetworkRoomPlayer>() != null)
|
||||
SceneLoadedForPlayer(conn, roomPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called on the server when a client adds a new player with NetworkClient.AddPlayer.
|
||||
/// <para>The default implementation for this function creates a new player object from the playerPrefab.</para>
|
||||
@ -597,6 +576,30 @@ public virtual bool OnRoomServerSceneLoadedForPlayer(NetworkConnectionToClient c
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is called on server from NetworkRoomPlayer.CmdChangeReadyState when client indicates change in Ready status.
|
||||
/// </summary>
|
||||
public virtual void ReadyStatusChanged()
|
||||
{
|
||||
int CurrentPlayers = 0;
|
||||
int ReadyPlayers = 0;
|
||||
|
||||
foreach (NetworkRoomPlayer item in roomSlots)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
CurrentPlayers++;
|
||||
if (item.readyToBegin)
|
||||
ReadyPlayers++;
|
||||
}
|
||||
}
|
||||
|
||||
if (CurrentPlayers == ReadyPlayers)
|
||||
CheckReadyToBegin();
|
||||
else
|
||||
allPlayersReady = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is called on the server when all the players in the room are ready.
|
||||
/// <para>The default implementation of this function uses ServerChangeScene() to switch to the game player scene. By implementing this callback you can customize what happens when all the players in the room are ready, such as adding a countdown or a confirmation for a group leader.</para>
|
||||
|
@ -105,6 +105,14 @@ public class #SCRIPTNAME# : NetworkRoomManager
|
||||
return base.OnRoomServerSceneLoadedForPlayer(conn, roomPlayer, gamePlayer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is called on server from NetworkRoomPlayer.CmdChangeReadyState when client indicates change in Ready status.
|
||||
/// </summary>
|
||||
public override void ReadyStatusChanged()
|
||||
{
|
||||
base.ReadyStatusChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is called on the server when all the players in the room are ready.
|
||||
/// <para>The default implementation of this function uses ServerChangeScene() to switch to the game player scene. By implementing this callback you can customize what happens when all the players in the room are ready, such as adding a countdown or a confirmation for a group leader.</para>
|
||||
|
Loading…
Reference in New Issue
Block a user