Skip to content

Commit

Permalink
Merge pull request #650 from vis2k/networkclient_static_2
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Make NetworkClient Great Again!
  • Loading branch information
miwarnec committed Mar 26, 2019
2 parents 3a8fa3f + 4d74f55 commit fac0542
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 226 deletions.
2 changes: 1 addition & 1 deletion Assets/Mirror/Components/NetworkAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public void SetTrigger(int hash)
{
if (hasAuthority && localPlayerAuthority)
{
if (NetworkClient.singleton != null && ClientScene.readyConnection != null)
if (ClientScene.readyConnection != null)
{
CmdOnAnimationTriggerServerMessage(hash);
}
Expand Down
14 changes: 7 additions & 7 deletions Assets/Mirror/Components/NetworkLobbyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public override void OnStopHost()

#region client handlers

public override void OnStartClient(NetworkClient lobbyClient)
public override void OnStartClient()
{
if (lobbyPlayerPrefab == null || lobbyPlayerPrefab.gameObject == null)
Debug.LogError("NetworkLobbyManager no LobbyPlayer prefab is registered. Please add a LobbyPlayer prefab.");
Expand All @@ -340,7 +340,7 @@ public override void OnStartClient(NetworkClient lobbyClient)
else
ClientScene.RegisterPrefab(playerPrefab);

OnLobbyStartClient(lobbyClient);
OnLobbyStartClient();
}

public override void OnClientConnect(NetworkConnection conn)
Expand Down Expand Up @@ -373,9 +373,9 @@ public override void OnClientChangeScene(string newSceneName)
{
if (LogFilter.Debug) Debug.LogFormat("OnClientChangeScene from {0} to {1}", SceneManager.GetActiveScene().name, newSceneName);

if (SceneManager.GetActiveScene().name == LobbyScene && newSceneName == GameplayScene && dontDestroyOnLoad && IsClientConnected() && client != null)
if (SceneManager.GetActiveScene().name == LobbyScene && newSceneName == GameplayScene && dontDestroyOnLoad && IsClientConnected())
{
GameObject lobbyPlayer = client?.connection?.playerController?.gameObject;
GameObject lobbyPlayer = NetworkClient.connection?.playerController?.gameObject;
if (lobbyPlayer != null)
{
lobbyPlayer.transform.SetParent(null);
Expand All @@ -385,14 +385,14 @@ public override void OnClientChangeScene(string newSceneName)
Debug.LogWarningFormat("OnClientChangeScene: lobbyPlayer is null");
}
else
if (LogFilter.Debug) Debug.LogFormat("OnClientChangeScene {0} {1} {2}", dontDestroyOnLoad, IsClientConnected(), client != null);
if (LogFilter.Debug) Debug.LogFormat("OnClientChangeScene {0} {1}", dontDestroyOnLoad, IsClientConnected());
}

public override void OnClientSceneChanged(NetworkConnection conn)
{
if (SceneManager.GetActiveScene().name == LobbyScene)
{
if (client.isConnected)
if (NetworkClient.isConnected)
CallOnClientEnterLobby();
}
else
Expand Down Expand Up @@ -452,7 +452,7 @@ public virtual void OnLobbyServerPlayersReady()

public virtual void OnLobbyClientDisconnect(NetworkConnection conn) {}

public virtual void OnLobbyStartClient(NetworkClient lobbyClient) {}
public virtual void OnLobbyStartClient() {}

public virtual void OnLobbyStopClient() {}

Expand Down
8 changes: 0 additions & 8 deletions Assets/Mirror/Runtime/ClientScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,6 @@ public static bool Ready(NetworkConnection conn)
return false;
}

public static NetworkClient ConnectLocalServer()
{
LocalClient newClient = new LocalClient();
NetworkServer.ActivateLocalClientScene();
newClient.InternalConnectLocalServer();
return newClient;
}

internal static void HandleClientDisconnect(NetworkConnection conn)
{
if (readyConnection == conn && ready)
Expand Down
68 changes: 0 additions & 68 deletions Assets/Mirror/Runtime/LocalClient.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/Mirror/Runtime/LocalClient.cs.meta

This file was deleted.

8 changes: 2 additions & 6 deletions Assets/Mirror/Runtime/LocalConnections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@ namespace Mirror
// sending messages on this connection causes the client's handler function to be invoked directly
class ULocalConnectionToClient : NetworkConnection
{
public LocalClient localClient;

public ULocalConnectionToClient(LocalClient localClient) : base ("localClient")
public ULocalConnectionToClient() : base ("localClient")
{
this.localClient = localClient;

// local player always has connectionId == 0
connectionId = 0;
}

internal override bool SendBytes(byte[] bytes, int channelId = Channels.DefaultReliable)
{
localClient.packetQueue.Enqueue(bytes);
NetworkClient.localClientPacketQueue.Enqueue(bytes);
return true;
}
}
Expand Down

0 comments on commit fac0542

Please sign in to comment.