コード例 #1
0
        /// <summary>
        /// Removes the old required control group field from the parent emitter's pool
        /// </summary>
        private void RemoveControlGroup()
        {
            ParticleSpawnTrigger?.RemoveRequiredParentFields(Parent);

            var groupIndex = (int)parentControlFlag;

            if (groupIndex >= ParticleFields.ChildrenFlags.Length)
            {
                return;
            }

            Parent?.RemoveRequiredField(ParticleFields.ChildrenFlags[groupIndex]);

            if (Parent != null)
            {
                Parent.DelayParticleDeath--;
            }
        }
コード例 #2
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);
        }