ClientScene: internal Shutdown moved to NetworkClient

This commit is contained in:
vis2k 2021-03-07 19:10:32 +08:00
parent ab1218fe17
commit 03f6ae59d3
5 changed files with 11 additions and 20 deletions

View File

@ -18,7 +18,7 @@ namespace Mirror
/// </summary>
public static class ClientScene
{
static bool isSpawnFinished;
internal static bool isSpawnFinished;
/// <summary> NetworkIdentity of the localPlayer </summary>
public static NetworkIdentity localPlayer { get; private set; }
@ -30,7 +30,7 @@ public static class ClientScene
// This connection can be used to send messages to the server. There can
// only be one ClientScene and ready connection at a time.
// TODO ready ? NetworkClient.connection : null??????
public static NetworkConnection readyConnection { get; private set; }
public static NetworkConnection readyConnection { get; internal set; }
[Obsolete("ClientScene.prefabs was moved to NetworkClient.prefabs")]
public static Dictionary<Guid, GameObject> prefabs => NetworkClient.prefabs;
@ -435,16 +435,5 @@ public static void DestroyAllClientObjects()
Debug.LogError("Could not DestroyAllClientObjects because spawned list was modified during loop, make sure you are not modifying NetworkIdentity.spawned by calling NetworkServer.Destroy or NetworkServer.Spawn in OnDestroy or OnDisable.");
}
}
// shutdown ////////////////////////////////////////////////////////////
internal static void Shutdown()
{
ClearSpawners();
spawnableObjects.Clear();
readyConnection = null;
ready = false;
isSpawnFinished = false;
DestroyAllClientObjects();
}
}
}

View File

@ -882,14 +882,20 @@ internal static void NetworkLateUpdate()
public static void Shutdown()
{
Debug.Log("Shutting down client.");
ClientScene.Shutdown();
ClearSpawners();
ClientScene.spawnableObjects.Clear();
ClientScene.readyConnection = null;
ClientScene.ready = false;
ClientScene.isSpawnFinished = false;
ClientScene.DestroyAllClientObjects();
connectState = ConnectState.None;
handlers.Clear();
// disconnect the client connection.
// we do NOT call Transport.Shutdown, because someone only called
// NetworkClient.Shutdown. we can't assume that the server is
// supposed to be shut down too!
Transport.activeTransport.ClientDisconnect();
if (Transport.activeTransport != null)
Transport.activeTransport.ClientDisconnect();
}
}
}

View File

@ -54,7 +54,7 @@ public void OneTimeSetUp()
[TearDown]
public virtual void TearDown()
{
ClientScene.Shutdown();
NetworkClient.Shutdown();
// reset asset id in case they are changed by tests
validPrefabNetworkIdentity.assetId = validPrefabGuid;

View File

@ -376,7 +376,6 @@ public void SendCommandInternal()
// clean up
RemoteCallHelper.RemoveDelegate(registeredHash);
// clear clientscene.readyconnection
ClientScene.Shutdown();
NetworkClient.Shutdown();
NetworkServer.Shutdown();
Transport.activeTransport = null;
@ -458,7 +457,6 @@ public void SendRPCInternal()
// clean up
RemoteCallHelper.RemoveDelegate(registeredHash);
// clear clientscene.readyconnection
ClientScene.Shutdown();
NetworkServer.RemoveLocalConnection();
NetworkClient.Shutdown();
NetworkServer.Shutdown();
@ -547,7 +545,6 @@ public void SendTargetRPCInternal()
// clean up
RemoteCallHelper.RemoveDelegate(registeredHash);
// clear clientscene.readyconnection
ClientScene.Shutdown();
NetworkServer.RemoveLocalConnection();
NetworkClient.Shutdown();
NetworkServer.Shutdown();

View File

@ -353,7 +353,6 @@ public void HostMode_IsFlags_Test()
// stop the client
NetworkClient.Shutdown();
NetworkServer.RemoveLocalConnection();
ClientScene.Shutdown();
// stop the server
NetworkServer.Shutdown();