Beispiel #1
0
        /// <inheritdoc />
        public unsafe override void SpawnNew(float dt, ParticleEmitter emitter)
        {
            if (isParentNameDirty)
            {
                RemoveControlGroup();

                Parent = emitter.CachedParticleSystem?.GetEmitterByName(ParentName);

                AddControlGroup();

                isParentNameDirty = false;
            }

            var spawnerState = GetUpdatedState(dt, emitter);

            if (spawnerState != SpawnerState.Active)
            {
                return;
            }

            // Get parent pool
            if (Parent == null)
            {
                return;
            }

            var parentPool           = Parent.Pool;
            var parentParticlesCount = parentPool.LivingParticles;

            if (parentParticlesCount == 0)
            {
                return;
            }

            var spawnControlGroup = GetSpawnControlField();

            if (!spawnControlGroup.IsValid())
            {
                return;
            }

            ParticleSpawnTrigger?.PrepareFromPool(parentPool);

            var randomSeedFieldParent = parentPool.GetField(ParticleFields.RandomSeed);

            int totalParticlesToEmit = 0;

            foreach (var parentParticle in parentPool)
            {
                uint particlesToEmit = 0;

                ParticleChildrenAttribute childrenAttribute = (*((ParticleChildrenAttribute *)parentParticle[spawnControlGroup]));
                var carryOver = childrenAttribute.CarryOver;

                var parentEventTriggered = ParticleSpawnTrigger?.HasTriggered(parentParticle) ?? 0f;
                if (parentEventTriggered > 0)
                {
                    var particlesToEmitFloat = SpawnCount.X;

                    if (randomSeedFieldParent.IsValid())
                    {
                        var randSeed = parentParticle.Get(randomSeedFieldParent);

                        particlesToEmitFloat = (SpawnCount.X + (SpawnCount.Y - SpawnCount.X) * randSeed.GetFloat(0));
                    }

                    particlesToEmitFloat *= parentEventTriggered;

                    particlesToEmit = (uint)Math.Floor(particlesToEmitFloat + carryOver);
                    carryOver      += (particlesToEmitFloat - particlesToEmit);
                }

                childrenAttribute.CarryOver       = carryOver;
                childrenAttribute.ParticlesToEmit = particlesToEmit;
                totalParticlesToEmit += (int)particlesToEmit;

                (*((ParticleChildrenAttribute *)parentParticle[spawnControlGroup])) = childrenAttribute;
            }

            emitter.EmitParticles(totalParticlesToEmit);
        }
Beispiel #2
0
 public ParticleChildrenAttribute(ParticleChildrenAttribute other)
 {
     flags     = other.flags;
     carryOver = other.carryOver;
 }