mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00: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);
|
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>
|
/// <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)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user