예제 #1
0
        /// <summary>
        /// Emits particles for a ParticleInteractionResult.
        /// </summary>
        /// <param name="interactionResult">The interaction result to use data from.</param>
        /// <param name="point">The world position to emit the particles at.</param>
        /// <param name="normal">The surface normal used to set the particle's rotation.</param>
        /// <param name="priority">The priority of the particles. Particles with a priority less than this will be "stolen" and used for this result.</param>
        /// <returns>The ImpactParticles that will be used to emit the particles. Will be null if no particles are available.</returns>
        public static ImpactParticlesBase EmitParticles(ParticleInteractionResult interactionResult, Vector3 point, Vector3 normal, int priority)
        {
            if (interactionResult.ParticlesTemplate == null)
            {
                return(null);
            }

            ImpactParticlePool pool = poolGroup.GetOrCreatePool(interactionResult.ParticlesTemplate, interactionResult.ParticlesTemplate.PoolSize);

            if (pool != null)
            {
                ImpactParticlesBase a = pool.GetObject();

                //If all objects are in use, try to get one with a lower priority
                if (a == null)
                {
                    a = pool.GetObject((p) => p.Priority < priority);
                }

                if (a != null)
                {
                    a.EmitParticles(interactionResult, point, normal, priority);
                }

                return(a);
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Updates for sliding and rolling and emits new particles if the particles are not looped.
        /// Will stop emitting if the new parameters don't produce valid data.
        /// </summary>
        /// <param name="newResult">The updated result.</param>
        public void KeepAlive(IInteractionResult newResult)
        {
            IsAlive = true;

            ParticleInteractionResult particleInteractionResult = newResult as ParticleInteractionResult;

            if (IsParticleLooped && particlesInstance != null)
            {
                particlesInstance.UpdateTransform(particleInteractionResult.OriginalData.Point, particleInteractionResult.OriginalData.Normal);
            }
            else
            {
                if (EmissionIntervalType == InteractionIntervalType.Time)
                {
                    intervalCounter += Time.fixedDeltaTime;
                }
                else
                {
                    intervalCounter = Vector3.Distance(particleInteractionResult.OriginalData.Point, previousEmissionPosition);
                }

                if (intervalCounter >= currentEmissionIntervalTarget)
                {
                    currentEmissionIntervalTarget = EmissionInterval.RandomInRange();
                    particlesInstance             = ImpactParticlePool.EmitParticles(this, particleInteractionResult.OriginalData.Point, particleInteractionResult.OriginalData.Normal, parent.Priority);

                    intervalCounter          = 0;
                    previousEmissionPosition = particleInteractionResult.OriginalData.Point;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Emit particles using our data.
        /// </summary>
        /// <param name="parent">The Impact Object that created this result.</param>
        public void Process(IImpactObject parent)
        {
            this.parent = parent;

            particlesInstance = ImpactParticlePool.EmitParticles(this, OriginalData.Point, OriginalData.Normal, InteractionResultExtensions.GetPriority(OriginalData.PriorityOverride, parent));
            IsAlive           = true;

            currentEmissionIntervalTarget = EmissionInterval.RandomInRange();

            //Dispose immediately for Collision interaction types
            if (OriginalData.InteractionType == InteractionData.InteractionTypeCollision)
            {
                Dispose();
            }
        }
예제 #4
0
 /// <summary>
 /// Creates an object pool instance for the particle prefab.
 /// </summary>
 public override void Preload()
 {
     ImpactParticlePool.PreloadPoolForParticle(ParticlePrefab);
     ImpactManagerInstance.CreateInteractionResultPool <Interactions.Particles.ParticleInteractionResult>(interactionResultPoolKey);
 }