Ejemplo n.º 1
0
        public void DespawnAll()
        {
            BeginBenchmark();
            {
                LeanPool.DespawnAll();

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

                // Despawn it
                LeanPool.Despawn(clone);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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");
        }
Ejemplo n.º 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");
        }
Ejemplo n.º 8
0
 public virtual void Despawn()
 {
     LeanPool.Despawn(gameObject);
 }