mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkConnection.DestroyOwnedObjects to move code out of NetworkServer
This commit is contained in:
parent
6111021252
commit
43030ac917
@ -371,5 +371,18 @@ internal void RemoveOwnedObject(NetworkIdentity obj)
|
||||
{
|
||||
clientOwnedObjects.Remove(obj.netId);
|
||||
}
|
||||
|
||||
internal void DestroyOwnedObjects()
|
||||
{
|
||||
// create a copy because the list might be modified when destroying
|
||||
HashSet<uint> tmp = new HashSet<uint>(clientOwnedObjects);
|
||||
foreach (uint netId in tmp)
|
||||
{
|
||||
if (NetworkIdentity.spawned.TryGetValue(netId, out NetworkIdentity netIdentity))
|
||||
{
|
||||
NetworkServer.Destroy(netIdentity.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1093,15 +1093,8 @@ internal static void SendSpawnMessage(NetworkIdentity identity, NetworkConnectio
|
||||
/// <param name="conn">The connections object to clean up for.</param>
|
||||
public static void DestroyPlayerForConnection(NetworkConnection conn)
|
||||
{
|
||||
// => destroy what we can destroy.
|
||||
HashSet<uint> tmp = new HashSet<uint>(conn.clientOwnedObjects);
|
||||
foreach (uint netId in tmp)
|
||||
{
|
||||
if (NetworkIdentity.spawned.TryGetValue(netId, out NetworkIdentity identity))
|
||||
{
|
||||
Destroy(identity.gameObject);
|
||||
}
|
||||
}
|
||||
// destroy all objects owned by this connection
|
||||
conn.DestroyOwnedObjects();
|
||||
|
||||
if (conn.identity != null)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user