diff --git a/Assets/Mirror/Core/NetworkIdentity.cs b/Assets/Mirror/Core/NetworkIdentity.cs index 1426fec15..68b0e95dc 100644 --- a/Assets/Mirror/Core/NetworkIdentity.cs +++ b/Assets/Mirror/Core/NetworkIdentity.cs @@ -707,9 +707,10 @@ internal void OnStopServer() } } - bool clientStarted; + public bool clientStarted; internal void OnStartClient() { + //Debug.Log($"clientStarted {connectionToClient} {clientStarted}"); if (clientStarted) return; clientStarted = true; diff --git a/Assets/Mirror/Core/NetworkManager.cs b/Assets/Mirror/Core/NetworkManager.cs index 22ae8cff1..737d4d780 100644 --- a/Assets/Mirror/Core/NetworkManager.cs +++ b/Assets/Mirror/Core/NetworkManager.cs @@ -404,7 +404,20 @@ public void StartClient() return; } - mode = NetworkManagerMode.ClientOnly; + if (string.IsNullOrWhiteSpace(networkAddress)) + { + Debug.LogError("Must set the Network Address field in the manager"); + return; + } + + if (mode == NetworkManagerMode.ServerOnly) + { + mode = NetworkManagerMode.Host; + FinishStartHost(); + return; + } + else + mode = NetworkManagerMode.ClientOnly; SetupClient(); @@ -413,11 +426,6 @@ public void StartClient() RegisterClientMessages(); - if (string.IsNullOrWhiteSpace(networkAddress)) - { - Debug.LogError("Must set the Network Address field in the manager"); - return; - } // Debug.Log($"NetworkManager StartClient address:{networkAddress}"); NetworkClient.Connect(networkAddress); @@ -1277,6 +1285,9 @@ void OnClientDisconnectInternal() // shutdown client NetworkClient.Shutdown(); + foreach (NetworkIdentity identity in NetworkServer.spawned.Values) + identity.clientStarted = false; + // Exit here if we're now in ServerOnly mode (StopClient called in Host mode). if (mode == NetworkManagerMode.ServerOnly) return; diff --git a/Assets/Mirror/Core/NetworkManagerHUD.cs b/Assets/Mirror/Core/NetworkManagerHUD.cs index c3785eac8..a87ecd78e 100644 --- a/Assets/Mirror/Core/NetworkManagerHUD.cs +++ b/Assets/Mirror/Core/NetworkManagerHUD.cs @@ -150,9 +150,17 @@ void StopButtons() } else if (NetworkServer.active) { + GUILayout.BeginHorizontal(); + // stop server if server-only if (GUILayout.Button("Stop Server")) manager.StopServer(); + + // start client if server-only, engaging host mode. + if (GUILayout.Button("Start Client")) + manager.StartClient(); + + GUILayout.EndHorizontal(); } } }