Fixed Lobby (#765)

This commit is contained in:
MrGadget 2019-04-07 15:48:17 -04:00 committed by vis2k
parent 263a9304e2
commit 3846e2f904
2 changed files with 14 additions and 37 deletions

View File

@ -58,12 +58,6 @@ public override void OnValidate()
base.OnValidate();
}
public void PlayerLoadedScene(NetworkConnection conn)
{
if (LogFilter.Debug) Debug.Log("NetworkLobbyManager OnSceneLoadedMessage");
SceneLoadedForPlayer(conn, conn.playerController.gameObject);
}
internal void ReadyStatusChanged()
{
int CurrentPlayers = 0;
@ -85,11 +79,20 @@ internal void ReadyStatusChanged()
allPlayersReady = false;
}
void SceneLoadedForPlayer(NetworkConnection conn, GameObject lobbyPlayerGameObject)
public override void OnServerReady(NetworkConnection conn)
{
// if not a lobby player.. dont replace it
if (lobbyPlayerGameObject.GetComponent<NetworkLobbyPlayer>() == null) return;
if (LogFilter.Debug) Debug.Log("NetworkLobbyManager OnServerReady");
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 (SceneManager.GetActiveScene().name == LobbyScene)
@ -97,7 +100,7 @@ void SceneLoadedForPlayer(NetworkConnection conn, GameObject lobbyPlayerGameObje
// cant be ready in lobby, add to ready list
PendingPlayer pending;
pending.conn = conn;
pending.lobbyPlayer = lobbyPlayerGameObject;
pending.lobbyPlayer = lobbyPlayer;
pendingPlayers.Add(pending);
return;
}
@ -113,7 +116,7 @@ void SceneLoadedForPlayer(NetworkConnection conn, GameObject lobbyPlayerGameObje
gamePlayer.name = playerPrefab.name;
}
if (!OnLobbyServerSceneLoadedForPlayer(lobbyPlayerGameObject, gamePlayer))
if (!OnLobbyServerSceneLoadedForPlayer(lobbyPlayer, gamePlayer))
return;
// 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.
foreach (PendingPlayer pending in pendingPlayers)
{
SceneLoadedForPlayer(pending.conn, pending.lobbyPlayer);
}
pendingPlayers.Clear();
}

View File

@ -23,19 +23,12 @@ public class NetworkLobbyPlayer : NetworkBehaviour
/// </summary>
public void Start()
{
if (isClient) SceneManager.sceneLoaded += ClientLoadedScene;
if (NetworkManager.singleton as NetworkLobbyManager)
OnClientEnterLobby();
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.");
}
void OnDisable()
{
SceneManager.sceneLoaded -= ClientLoadedScene;
}
#endregion
#region Commands
@ -48,13 +41,6 @@ public void CmdChangeReadyState(bool ReadyState)
lobby?.ReadyStatusChanged();
}
[Command]
public void CmdSendLevelLoaded()
{
NetworkLobbyManager lobby = NetworkManager.singleton as NetworkLobbyManager;
lobby?.PlayerLoadedScene(GetComponent<NetworkIdentity>().connectionToClient);
}
#endregion
#region SyncVar Hooks
@ -74,16 +60,6 @@ public virtual void OnClientExitLobby() {}
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
#region Optional UI