public void DespawnAll() { BeginBenchmark(); { LeanPool.DespawnAll(); spawnedPrefabs.Clear(); } EndBenchmark("DespawnAll"); }
public void DespawnPrefab() { if (spawnedPrefabs.Count > 0) { // Get the last clone var clone = spawnedPrefabs.Pop(); // Despawn it LeanPool.Despawn(clone); } }
public void SpawnPrefab() { // Randomly calculate a position var position = (Vector3)Random.insideUnitCircle * 6.0f; // Spawn a prefab clone var clone = LeanPool.Spawn(Prefab, position, Quaternion.identity, null); // Despawn it with a delay LeanPool.Despawn(clone, DespawnDelay); }
public void SpawnPrefab() { var position = (Vector3)Random.insideUnitCircle * 6.0f; var clone = LeanPool.Spawn(Prefab, position, Quaternion.identity, null); // Add the clone to the clones stack if it doesn't exist // If this prefab can be recycled then it could already exist if (spawnedPrefabs.Contains(clone) == false) { spawnedPrefabs.Push(clone); } }
protected virtual void OnDestroy() { // If OnDestroy is called then the scene is likely changing, so we detach the spawned prefabs from the global links dictionary to prevent issues. foreach (var clone in spawnedClonesList) { LeanPool.Detach(clone, false); } foreach (var clone in spawnedClonesHashSet) { LeanPool.Detach(clone, false); } }
public void Despawn() { BeginBenchmark(); { // NOTE: Despawning in reverse spawn order is faster than spawn order for (var i = spawnedPrefabs.Count - 1; i >= 0; i--) { LeanPool.Despawn(spawnedPrefabs[i]); } spawnedPrefabs.Clear(); } EndBenchmark("Despawn"); }
public void Spawn() { BeginBenchmark(); { for (var i = 0; i < Count; i++) { var position = (Vector3)Random.insideUnitCircle * 6.0f; var clone = LeanPool.Spawn(Prefab, position, Quaternion.identity, null); spawnedPrefabs.Add(clone); } } EndBenchmark("Spawn"); }
public virtual void Despawn() { LeanPool.Despawn(gameObject); }