예제 #1
0
        protected override void OnEntityComponentAdding(Entity entity, ParticleSystemComponent particleSystemComponent, RenderParticleSystem renderParticleSystem)
        {
            var emitters       = particleSystemComponent.ParticleSystem.Emitters;
            var emitterCount   = emitters.Count;
            var renderEmitters = new RenderParticleEmitter[emitterCount];

            for (int index = 0; index < emitterCount; index++)
            {
                var renderEmitter = new RenderParticleEmitter
                {
                    ParticleEmitter      = emitters[index],
                    RenderParticleSystem = renderParticleSystem,
                    RenderGroup          = particleSystemComponent.RenderGroup,
                };

                renderEmitters[index] = renderEmitter;
                VisibilityGroup.RenderObjects.Add(renderEmitter);
            }

            renderParticleSystem.Emitters = renderEmitters;
        }
예제 #2
0
        private void CheckEmitters(RenderParticleSystem renderParticleSystem)
        {
            if (renderParticleSystem == null)
            {
                return;
            }

            var emitters = renderParticleSystem.ParticleSystem.Emitters;

            var emitterCount = 0;

            if (renderParticleSystem.ParticleSystem.Enabled)
            {
                foreach (var particleEmitter in emitters)
                {
                    if (particleEmitter.Enabled)
                    {
                        emitterCount++;
                    }
                }
            }

            if (emitterCount == (renderParticleSystem.Emitters?.Length ?? 0))
            {
                return;
            }

            // Remove old emitters
            if (renderParticleSystem.Emitters != null)
            {
                foreach (var renderEmitter in renderParticleSystem.Emitters)
                {
                    VisibilityGroup.RenderObjects.Remove(renderEmitter);
                }
            }

            renderParticleSystem.Emitters = null;

            // Add new emitters
            var enabledEmitterIndex = 0;
            var renderEmitters      = new RenderParticleEmitter[emitterCount];

            for (int index = 0; index < emitterCount; index++)
            {
                while (enabledEmitterIndex < emitters.Count && !emitters[enabledEmitterIndex].Enabled)
                {
                    enabledEmitterIndex++;
                }

                if (enabledEmitterIndex >= emitters.Count)
                {
                    continue;
                }

                var renderEmitter = new RenderParticleEmitter
                {
                    ParticleEmitter      = emitters[enabledEmitterIndex],
                    RenderParticleSystem = renderParticleSystem,
                };

                renderEmitters[index] = renderEmitter;
                VisibilityGroup.RenderObjects.Add(renderEmitter);

                enabledEmitterIndex++;
            }

            renderParticleSystem.Emitters = renderEmitters;
        }