Exemple #1
0
        // ParticleSystem (Shuriken) Version...
        private IEnumerator ListenForEmitDespawn(ParticleSystem emitter)
        {
            // Wait for the delay time to complete
            // Waiting the extra frame seems to be more stable and means at least one
            //  frame will always pass
            yield return(new WaitForSeconds(emitter.startDelay + 0.25f));

            // Do nothing until all particles die or the safecount hits a max value
            float safetimer = 0;   // Just in case! See Spawn() for more info

            while (emitter.IsAlive(true))
            {
                if (!PoolManagerUtils.activeInHierarchy(emitter.gameObject))
                {
                    emitter.Clear(true);
                    yield break;  // Do nothing, already despawned. Quit.
                }

                safetimer += Time.deltaTime;
                if (safetimer > this.maxParticleDespawnTime)
                {
                    Debug.LogWarning
                    (
                        string.Format
                        (
                            "SpawnPool {0}: " +
                            "Timed out while listening for all particles to die. " +
                            "Waited for {1}sec.",
                            this.poolName,
                            this.maxParticleDespawnTime
                        )
                    );
                }

                yield return(null);
            }

            // Turn off emit before despawning
            //emitter.Clear(true);
            this.Despawn(emitter.transform);
        }