internal void UnregisterObject(Object obj) { lock (ManagedObjects) { if (!ManagedObjects.Contains(obj)) { return; } ManagedObjects.Remove(obj); if (obj is GameObject gameObject) { if ((gameObject.Id.Flags & ObjectIdFlags.Spawned) != 0) { SpawnedObjects.Remove(gameObject); } } var updated = UpdatedObjects.FirstOrDefault(u => u.Associate == obj); if (updated == default) { return; } UpdatedObjects.Remove(updated); } }
public void Update() { foreach (var ObjectToCheck in SpawnedObjects.ToList()) { if (!ObjectToCheck) { SpawnedObjects.Remove(ObjectToCheck); } } }
private void OnNetworkDestroy(NetworkWriter writer) { if (IsServer) { return; } int instanceID = writer.ReadInt16(); NetworkIdentity identity = NetworkIdentityManager.Instance.Get(instanceID); SpawnedObjects?.Remove(identity.gameObject); DestroyedGameObject?.Invoke(identity); Object.Destroy(identity.gameObject); }
private void OnDestroyPlayer(NetworkConnection conn) { NetworkPlayerObject playerObject = PlayerObjects?.Find(x => x.ConnectionID == conn.ConnectionID); if (playerObject != null) { if (SpawnedObjects?.Contains(playerObject.GameObject) ?? false) { SpawnedObjects.Remove(playerObject.GameObject); } DestroyedGameObject?.Invoke(playerObject.NetworkIdentity); Object.Destroy(playerObject.GameObject); PlayerObjects.Remove(playerObject); m_PlayerObjectCache?.Remove(conn.ConnectionID); } if (m_BufferedPlayersCreations?.ContainsKey(conn.ConnectionID) ?? false) { m_BufferedPlayersCreations.Remove(conn.ConnectionID); } if (m_BufferedOwnerCreations?.ContainsKey(conn.ConnectionID) ?? false) { m_BufferedOwnerCreations.Remove(conn.ConnectionID); } if (m_AuthroityObjects?.ContainsKey(conn) ?? false) { foreach (NetworkIdentity identity in m_AuthroityObjects[conn]) { if (identity != null) { Destroy(identity.gameObject); } } m_AuthroityObjects.Remove(conn); } m_BufferedPlayerConnections?.Remove(conn); }
private static void DestroyCustomObjects() { while (SpawnedObjects.Count != 0) { GameObject gameObject = SpawnedObjects[0]; SpawnedObjects.Remove(gameObject); UnityEngine.Object.Destroy(gameObject); foreach (TubeBloomPrePassLight tubeBloomPrePassLight in gameObject.GetComponentsInChildren <TubeBloomPrePassLight>(true)) { //Unity requires this to be present, otherwise Unregister won't be called. Memory leaks may occour if this is removed. tubeBloomPrePassLight.InvokeMethod <object, BloomPrePassLight>("UnregisterLight"); } } while (SpawnedComponents.Count != 0) { Component component = SpawnedComponents[0]; SpawnedComponents.Remove(component); UnityEngine.Object.Destroy(component); } }
/// <summary> /// Destroy a networked object. /// </summary> /// <param name="gameObject"></param> public void Destroy(GameObject gameObject) { if (!IsServer) { return; } if (!ServerValidateDestroy(gameObject, out NetworkIdentity identity)) { return; } byte[] data = BitConverter.GetBytes((short)identity.InstanceID); NetworkController.Instance.SendToAll(NetworkController.ReliableSequencedChannel, DestroyMsg, data); DestroyedGameObject?.Invoke(identity); SpawnedObjects.Remove(identity.gameObject); Object.Destroy(gameObject); }
void ISpawner.Remove(ISpawnable spawn) { SpawnedObjects.Remove(spawn); CheckTimer(); }
public override void Despawn(RunObject ro) { Pool.Despawn(ro.transform); SpawnedObjects.Remove(ro); ro.OnObjectDespawned(); }