예제 #1
0
        public void DespawnAll()
        {
            BeginBenchmark();
            {
                LeanPool.DespawnAll();

                spawnedPrefabs.Clear();
            }
            EndBenchmark("DespawnAll");
        }
예제 #2
0
        public void DespawnPrefab()
        {
            if (spawnedPrefabs.Count > 0)
            {
                // Get the last clone
                var clone = spawnedPrefabs.Pop();

                // Despawn it
                LeanPool.Despawn(clone);
            }
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
            }
        }
예제 #6
0
        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");
        }
예제 #7
0
        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");
        }
예제 #8
0
 public virtual void Despawn()
 {
     LeanPool.Despawn(gameObject);
 }