/// <summary> /// Despawns a object. /// </summary> /// <param name="pObject">The object to despawn.</param> /// <param name="destroyObject">Should the despawned object also get destroyed?</param> /// <param name="nullcheck">Should the list get interated to removed null values?</param> /// <returns>True if the object was removed correctly.</returns> private bool DespawnInternal(GameObject pObject, bool destroyObject, bool nullcheck) { if (nullcheck) { ActiveObject.RemoveAll(g => g == null); } if (ActiveObject.Remove(pObject)) { if (OnObjectDeSpawn != null) { OnObjectDeSpawn.Invoke(pObject, this); } if (destroyObject) { if (pObject.GetComponent <IDespawnEvent>() != null) { OnObjectDeSpawn -= new DespawnEvent(pObject.GetComponent <IDespawnEvent>().OnDespawned); } Destroy(pObject); } else { pObject.SetActive(false); DespawnedElements.Enqueue(pObject); } return(true); } return(false); }
public bool Despawn(GameObject pObject, bool DestroyObject = false) { if (ActiveObject.Remove(pObject)) { if (DestroyObject) { Destroy(pObject); } else { pObject.SetActive(false); DespawnedElements.Enqueue(pObject); } return(true); } return(false); }