mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
Fixed Lobby (#765)
This commit is contained in:
parent
263a9304e2
commit
3846e2f904
@ -58,12 +58,6 @@ public override void OnValidate()
|
|||||||
base.OnValidate();
|
base.OnValidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayerLoadedScene(NetworkConnection conn)
|
|
||||||
{
|
|
||||||
if (LogFilter.Debug) Debug.Log("NetworkLobbyManager OnSceneLoadedMessage");
|
|
||||||
SceneLoadedForPlayer(conn, conn.playerController.gameObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void ReadyStatusChanged()
|
internal void ReadyStatusChanged()
|
||||||
{
|
{
|
||||||
int CurrentPlayers = 0;
|
int CurrentPlayers = 0;
|
||||||
@ -85,11 +79,20 @@ internal void ReadyStatusChanged()
|
|||||||
allPlayersReady = false;
|
allPlayersReady = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneLoadedForPlayer(NetworkConnection conn, GameObject lobbyPlayerGameObject)
|
public override void OnServerReady(NetworkConnection conn)
|
||||||
{
|
{
|
||||||
// if not a lobby player.. dont replace it
|
if (LogFilter.Debug) Debug.Log("NetworkLobbyManager OnServerReady");
|
||||||
if (lobbyPlayerGameObject.GetComponent<NetworkLobbyPlayer>() == null) return;
|
base.OnServerReady(conn);
|
||||||
|
|
||||||
|
GameObject lobbyPlayer = conn?.playerController?.gameObject;
|
||||||
|
|
||||||
|
// if null or not a lobby player, dont replace it
|
||||||
|
if (lobbyPlayer?.GetComponent<NetworkLobbyPlayer>() != null)
|
||||||
|
SceneLoadedForPlayer(conn, lobbyPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneLoadedForPlayer(NetworkConnection conn, GameObject lobbyPlayer)
|
||||||
|
{
|
||||||
if (LogFilter.Debug) Debug.LogFormat("NetworkLobby SceneLoadedForPlayer scene: {0} {1}", SceneManager.GetActiveScene().name, conn);
|
if (LogFilter.Debug) Debug.LogFormat("NetworkLobby SceneLoadedForPlayer scene: {0} {1}", SceneManager.GetActiveScene().name, conn);
|
||||||
|
|
||||||
if (SceneManager.GetActiveScene().name == LobbyScene)
|
if (SceneManager.GetActiveScene().name == LobbyScene)
|
||||||
@ -97,7 +100,7 @@ void SceneLoadedForPlayer(NetworkConnection conn, GameObject lobbyPlayerGameObje
|
|||||||
// cant be ready in lobby, add to ready list
|
// cant be ready in lobby, add to ready list
|
||||||
PendingPlayer pending;
|
PendingPlayer pending;
|
||||||
pending.conn = conn;
|
pending.conn = conn;
|
||||||
pending.lobbyPlayer = lobbyPlayerGameObject;
|
pending.lobbyPlayer = lobbyPlayer;
|
||||||
pendingPlayers.Add(pending);
|
pendingPlayers.Add(pending);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -113,7 +116,7 @@ void SceneLoadedForPlayer(NetworkConnection conn, GameObject lobbyPlayerGameObje
|
|||||||
gamePlayer.name = playerPrefab.name;
|
gamePlayer.name = playerPrefab.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!OnLobbyServerSceneLoadedForPlayer(lobbyPlayerGameObject, gamePlayer))
|
if (!OnLobbyServerSceneLoadedForPlayer(lobbyPlayer, gamePlayer))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// replace lobby player with game player
|
// replace lobby player with game player
|
||||||
@ -275,9 +278,7 @@ public override void OnServerSceneChanged(string sceneName)
|
|||||||
{
|
{
|
||||||
// call SceneLoadedForPlayer on any players that become ready while we were loading the scene.
|
// call SceneLoadedForPlayer on any players that become ready while we were loading the scene.
|
||||||
foreach (PendingPlayer pending in pendingPlayers)
|
foreach (PendingPlayer pending in pendingPlayers)
|
||||||
{
|
|
||||||
SceneLoadedForPlayer(pending.conn, pending.lobbyPlayer);
|
SceneLoadedForPlayer(pending.conn, pending.lobbyPlayer);
|
||||||
}
|
|
||||||
|
|
||||||
pendingPlayers.Clear();
|
pendingPlayers.Clear();
|
||||||
}
|
}
|
||||||
|
@ -23,19 +23,12 @@ public class NetworkLobbyPlayer : NetworkBehaviour
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
if (isClient) SceneManager.sceneLoaded += ClientLoadedScene;
|
|
||||||
|
|
||||||
if (NetworkManager.singleton as NetworkLobbyManager)
|
if (NetworkManager.singleton as NetworkLobbyManager)
|
||||||
OnClientEnterLobby();
|
OnClientEnterLobby();
|
||||||
else
|
else
|
||||||
Debug.LogError("LobbyPlayer could not find a NetworkLobbyManager. The LobbyPlayer requires a NetworkLobbyManager object to function. Make sure that there is one in the scene.");
|
Debug.LogError("LobbyPlayer could not find a NetworkLobbyManager. The LobbyPlayer requires a NetworkLobbyManager object to function. Make sure that there is one in the scene.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDisable()
|
|
||||||
{
|
|
||||||
SceneManager.sceneLoaded -= ClientLoadedScene;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Commands
|
#region Commands
|
||||||
@ -48,13 +41,6 @@ public void CmdChangeReadyState(bool ReadyState)
|
|||||||
lobby?.ReadyStatusChanged();
|
lobby?.ReadyStatusChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command]
|
|
||||||
public void CmdSendLevelLoaded()
|
|
||||||
{
|
|
||||||
NetworkLobbyManager lobby = NetworkManager.singleton as NetworkLobbyManager;
|
|
||||||
lobby?.PlayerLoadedScene(GetComponent<NetworkIdentity>().connectionToClient);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region SyncVar Hooks
|
#region SyncVar Hooks
|
||||||
@ -74,16 +60,6 @@ public virtual void OnClientExitLobby() {}
|
|||||||
|
|
||||||
public virtual void OnClientReady(bool readyState) {}
|
public virtual void OnClientReady(bool readyState) {}
|
||||||
|
|
||||||
public virtual void ClientLoadedScene(Scene arg0, LoadSceneMode arg1)
|
|
||||||
{
|
|
||||||
NetworkLobbyManager lobby = NetworkManager.singleton as NetworkLobbyManager;
|
|
||||||
if (lobby != null && SceneManager.GetActiveScene().name == lobby.LobbyScene)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (this != null && isLocalPlayer)
|
|
||||||
CmdSendLevelLoaded();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Optional UI
|
#region Optional UI
|
||||||
|
Loading…
Reference in New Issue
Block a user