Skip to content

Commit

Permalink
fix: OnClientReady is called and passed the appropriate ready state v…
Browse files Browse the repository at this point in the history
…alue in NetworkLobbyPlayer (#618)
  • Loading branch information
Katori authored and paulpach committed Mar 21, 2019
1 parent 28b067d commit c9eac57
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions Assets/Mirror/Components/NetworkLobbyPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ public class NetworkLobbyPlayer : NetworkBehaviour
{
public bool ShowLobbyGUI = true;

[SyncVar]
[SyncVar(hook=nameof(ReadyStateChanged))]
public bool ReadyToBegin;

[SyncVar]
public int Index;

#region Unity Callbacks

/// <summary>
/// Do not use Start - Override OnStartrHost / OnStartClient instead!
/// </summary>
Expand All @@ -34,15 +36,9 @@ void OnDisable()
SceneManager.sceneLoaded -= ClientLoadedScene;
}

public virtual void ClientLoadedScene(Scene arg0, LoadSceneMode arg1)
{
NetworkLobbyManager lobby = NetworkManager.singleton as NetworkLobbyManager;
if (lobby != null && SceneManager.GetActiveScene().name == lobby.LobbyScene)
return;
#endregion

if (this != null && isLocalPlayer)
CmdSendLevelLoaded();
}
#region Commands

[Command]
public void CmdChangeReadyState(bool ReadyState)
Expand All @@ -59,17 +55,39 @@ public void CmdSendLevelLoaded()
lobby?.PlayerLoadedScene(GetComponent<NetworkIdentity>().connectionToClient);
}

#region lobby client virtuals
#endregion

#region SyncVar Hooks

private void ReadyStateChanged(bool NewReadyState)
{
ReadyToBegin = NewReadyState;
OnClientReady(ReadyToBegin);
}

#endregion

#region Lobby Client Virtuals

public virtual void OnClientEnterLobby() {}

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
#region Optional UI

public virtual void OnGUI()
{
Expand Down

0 comments on commit c9eac57

Please sign in to comment.