Beispiel #1
0
        /// <summary>Plays the particle effect, but replaces the material on the particle with the one specified (mat).</summary>
        public void PlayEffect(ParticleSystem effect, Vector3 pos, Quaternion rot, int parentId, Material mat)
        {
            if (effect == null) return;

            // Check if we're at the maximum active particle limit. If so, ignore the request to play the particle effect.
            if (IsMaxActiveParticles) return;

            // Check if we've reached the max particle limit per destructible object for this object already.
            int parentParticleCount = ActiveParticles.Count(x => x.ParentId == parentId);
            if (parentParticleCount > maxPerDestructible) return;

            // Instantiate and add to the ActiveParticles counter
            GameObject spawn = ObjectPool.Instance.Spawn(effect.gameObject, pos, rot);
            if (spawn == null || spawn.GetComponent<ParticleSystem>() == null) return;
            ActiveParticle aParticle = new ActiveParticle() { GameObject = spawn, InstantiatedTime = Time.time, ParentId = parentId };
            Array.Resize(ref activeParticles, activeParticles.Length + 1);
            ActiveParticles[activeParticles.Length - 1] = aParticle;

            // Replace the materials on the particle effect with the one passed in.
            if (mat != null && spawn.GetComponent<ParticleSystem>() != null)
            {
                foreach (ParticleSystemRenderer ps in spawn.GetComponentsInChildren<ParticleSystemRenderer>())
                {
                    if (ps.renderMode == ParticleSystemRenderMode.Mesh)
                        ps.sharedMaterial = mat;
                }
            }
        }
Beispiel #2
0
        private ParticleManager() { } // hide constructor

        void Awake()
        {
            ActiveParticles = new ActiveParticle[0];
            Instance = this;
            nextUpdate = Time.time + updateFrequency;
        }