mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
feat(NetworkManager):Allow host client to start late or rejoin
This commit is contained in:
parent
f83d568e60
commit
a4c31e7c49
@ -707,9 +707,10 @@ internal void OnStopServer()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool clientStarted;
|
public bool clientStarted;
|
||||||
internal void OnStartClient()
|
internal void OnStartClient()
|
||||||
{
|
{
|
||||||
|
//Debug.Log($"clientStarted {connectionToClient} {clientStarted}");
|
||||||
if (clientStarted) return;
|
if (clientStarted) return;
|
||||||
|
|
||||||
clientStarted = true;
|
clientStarted = true;
|
||||||
|
@ -404,6 +404,19 @@ public void StartClient()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
mode = NetworkManagerMode.ClientOnly;
|
||||||
|
|
||||||
SetupClient();
|
SetupClient();
|
||||||
@ -413,11 +426,6 @@ public void StartClient()
|
|||||||
|
|
||||||
RegisterClientMessages();
|
RegisterClientMessages();
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(networkAddress))
|
|
||||||
{
|
|
||||||
Debug.LogError("Must set the Network Address field in the manager");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Debug.Log($"NetworkManager StartClient address:{networkAddress}");
|
// Debug.Log($"NetworkManager StartClient address:{networkAddress}");
|
||||||
|
|
||||||
NetworkClient.Connect(networkAddress);
|
NetworkClient.Connect(networkAddress);
|
||||||
@ -1277,6 +1285,9 @@ void OnClientDisconnectInternal()
|
|||||||
// shutdown client
|
// shutdown client
|
||||||
NetworkClient.Shutdown();
|
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).
|
// Exit here if we're now in ServerOnly mode (StopClient called in Host mode).
|
||||||
if (mode == NetworkManagerMode.ServerOnly) return;
|
if (mode == NetworkManagerMode.ServerOnly) return;
|
||||||
|
|
||||||
|
@ -150,9 +150,17 @@ void StopButtons()
|
|||||||
}
|
}
|
||||||
else if (NetworkServer.active)
|
else if (NetworkServer.active)
|
||||||
{
|
{
|
||||||
|
GUILayout.BeginHorizontal();
|
||||||
|
|
||||||
// stop server if server-only
|
// stop server if server-only
|
||||||
if (GUILayout.Button("Stop Server"))
|
if (GUILayout.Button("Stop Server"))
|
||||||
manager.StopServer();
|
manager.StopServer();
|
||||||
|
|
||||||
|
// start client if server-only, engaging host mode.
|
||||||
|
if (GUILayout.Button("Start Client"))
|
||||||
|
manager.StartClient();
|
||||||
|
|
||||||
|
GUILayout.EndHorizontal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user