NetworkConnection.DestroyOwnedObjects to move code out of NetworkServer

This commit is contained in:
vis2k 2020-01-08 11:04:17 +01:00
parent 6111021252
commit 43030ac917
2 changed files with 15 additions and 9 deletions

View File

@ -371,5 +371,18 @@ internal void RemoveOwnedObject(NetworkIdentity obj)
{ {
clientOwnedObjects.Remove(obj.netId); 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);
}
}
}
} }
} }

View File

@ -1093,15 +1093,8 @@ internal static void SendSpawnMessage(NetworkIdentity identity, NetworkConnectio
/// <param name="conn">The connections object to clean up for.</param> /// <param name="conn">The connections object to clean up for.</param>
public static void DestroyPlayerForConnection(NetworkConnection conn) public static void DestroyPlayerForConnection(NetworkConnection conn)
{ {
// => destroy what we can destroy. // destroy all objects owned by this connection
HashSet<uint> tmp = new HashSet<uint>(conn.clientOwnedObjects); conn.DestroyOwnedObjects();
foreach (uint netId in tmp)
{
if (NetworkIdentity.spawned.TryGetValue(netId, out NetworkIdentity identity))
{
Destroy(identity.gameObject);
}
}
if (conn.identity != null) if (conn.identity != null)
{ {