Пример #1
0
        /// <summary>
        /// Calculates the effect from a Manipulator.
        /// </summary>
        /// <param name="playgroundParticles">Playground particles.</param>
        /// <param name="thisManipulator">This manipulator.</param>
        /// <param name="p">Particle index.</param>
        /// <param name="t">Delta time.</param>
        /// <param name="life">Lifetime.</param>
        /// <param name="particlePosition">Particle position.</param>
        /// <param name="manipulatorPosition">Manipulator position.</param>
        /// <param name="manipulatorDistance">Manipulator distance.</param>
        /// <param name="localSpace">Is calculation in local space?</param>
        public static void CalculateManipulator(PlaygroundParticlesC playgroundParticles, ManipulatorObjectC thisManipulator, int p, float t, float life, Vector3 particlePosition, Vector3 manipulatorPosition, bool localSpace)
        {
            if (thisManipulator.enabled && thisManipulator.transform.available && thisManipulator.strength!=0 && thisManipulator.LifetimeFilter(life, playgroundParticles.lifetime) && thisManipulator.ParticleFilter (p, playgroundParticles.particleCount)) {

                bool contains = thisManipulator.Contains(localSpace?(playgroundParticles.particleSystemRotation*particlePosition):particlePosition, localSpace?(playgroundParticles.particleSystemRotation*manipulatorPosition):manipulatorPosition);

                // Is this a particle which shouldn't be affected by this manipulator?
                if (contains && (playgroundParticles.playgroundCache.excludeFromManipulatorId[p]==thisManipulator.manipulatorId || thisManipulator.nonAffectedParticles.Count>0 && thisManipulator.ContainsNonAffectedParticle(playgroundParticles.particleSystemId, p))) {
                    return;
                }

                // Manipulator events
                if (thisManipulator.trackParticles) {

                    // Particle entering
                    if (contains) {
                        if ((thisManipulator.trackingMethod==TrackingMethod.ManipulatorId && !thisManipulator.IsSameId(playgroundParticles.playgroundCache.manipulatorId[p])) || (thisManipulator.trackingMethod==TrackingMethod.ParticleId && !thisManipulator.ContainsParticle(playgroundParticles.particleSystemId, p))) {
                            playgroundParticles.playgroundCache.manipulatorId[p] = thisManipulator.manipulatorId;
                            thisManipulator.AddParticle(playgroundParticles.particleSystemId, p);
                            if (thisManipulator.sendEventEnter) {
                                playgroundParticles.UpdateEventParticle(thisManipulator.manipulatorEventParticle, p);
                                thisManipulator.SendParticleEventEnter();
                            }
                        }
                    } else {

                        // Particle exiting
                        if ((thisManipulator.trackingMethod==TrackingMethod.ManipulatorId && thisManipulator.IsSameId(playgroundParticles.playgroundCache.manipulatorId[p])) || (thisManipulator.trackingMethod==TrackingMethod.ParticleId && thisManipulator.ContainsParticle(playgroundParticles.particleSystemId, p))) {
                            playgroundParticles.playgroundCache.manipulatorId[p] = 0;
                            thisManipulator.RemoveParticle(playgroundParticles.particleSystemId, p);
                            if (thisManipulator.sendEventExit) {
                                playgroundParticles.UpdateEventParticle(thisManipulator.manipulatorEventParticle, p);
                                thisManipulator.SendParticleEventExit();
                            }
                        }
                    }
                }

                float manipulatorDistance = 0;

                if (!playgroundParticles.onlySourcePositioning && !playgroundParticles.playgroundCache.noForce[p]) {
                    // Attractors
                    if (thisManipulator.type==MANIPULATORTYPEC.Attractor) {
                        if (contains) {
                            manipulatorDistance = thisManipulator.strengthDistanceEffect>0?Vector3.Distance (manipulatorPosition, playgroundParticles.playgroundCache.position[p])/thisManipulator.strengthDistanceEffect:10f;
                            playgroundParticles.playgroundCache.velocity[p] = Vector3.Lerp(playgroundParticles.playgroundCache.velocity[p], (manipulatorPosition-particlePosition)*(thisManipulator.strength/manipulatorDistance), t*(thisManipulator.strength/manipulatorDistance)/thisManipulator.strengthSmoothing);
                        }
                    } else

                    // Attractors Gravitational
                    if (thisManipulator.type==MANIPULATORTYPEC.AttractorGravitational) {
                        if (contains) {
                            manipulatorDistance = thisManipulator.strengthDistanceEffect>0?Vector3.Distance (manipulatorPosition, playgroundParticles.playgroundCache.position[p])/thisManipulator.strengthDistanceEffect:10f;
                            playgroundParticles.playgroundCache.velocity[p] = Vector3.Lerp(playgroundParticles.playgroundCache.velocity[p], (manipulatorPosition-particlePosition)*thisManipulator.strength/manipulatorDistance, t/thisManipulator.strengthSmoothing);
                        }
                    } else

                    // Repellents
                    if (thisManipulator.type==MANIPULATORTYPEC.Repellent) {
                        if (contains) {
                            manipulatorDistance = thisManipulator.strengthDistanceEffect>0?Vector3.Distance (manipulatorPosition, playgroundParticles.playgroundCache.position[p])/thisManipulator.strengthDistanceEffect:10f;
                            playgroundParticles.playgroundCache.velocity[p] = Vector3.Lerp(playgroundParticles.playgroundCache.velocity[p], (particlePosition-manipulatorPosition)*(thisManipulator.strength/manipulatorDistance), t*(thisManipulator.strength/manipulatorDistance)/thisManipulator.strengthSmoothing);
                        }
                    } else

                    // Vortex
                    if (thisManipulator.type==MANIPULATORTYPEC.Vortex) {
                        if (contains) {
                            manipulatorDistance = thisManipulator.strengthDistanceEffect>0?Vector3.Distance (manipulatorPosition, playgroundParticles.playgroundCache.position[p])/thisManipulator.strengthDistanceEffect:10f;
                            playgroundParticles.playgroundCache.velocity[p] = Vector3.Lerp(playgroundParticles.playgroundCache.velocity[p], ((manipulatorPosition-particlePosition)*thisManipulator.strength/manipulatorDistance)-Vector3.Cross(thisManipulator.transform.up, (manipulatorPosition-particlePosition))*thisManipulator.strength/manipulatorDistance, (t*thisManipulator.strength/manipulatorDistance)/thisManipulator.strengthSmoothing);
                        }
                    }
                }

                // Properties
                if (thisManipulator.type==MANIPULATORTYPEC.Property) {
                    manipulatorDistance = thisManipulator.strengthDistanceEffect>0?Vector3.SqrMagnitude (manipulatorPosition - particlePosition)/thisManipulator.strengthDistanceEffect:10f;
                    PropertyManipulator(playgroundParticles, thisManipulator, thisManipulator.property, p, t, particlePosition, manipulatorPosition, manipulatorDistance, localSpace, contains);
                } else

                // Combined
                if (thisManipulator.type==MANIPULATORTYPEC.Combined) {
                    manipulatorDistance = thisManipulator.strengthDistanceEffect>0?Vector3.SqrMagnitude (manipulatorPosition - particlePosition)/thisManipulator.strengthDistanceEffect:10f;
                    for (int i = 0; i<thisManipulator.properties.Count; i++)
                        PropertyManipulator(playgroundParticles, thisManipulator, thisManipulator.properties[i], p, t, particlePosition, manipulatorPosition, manipulatorDistance, localSpace, contains);
                }
            }
        }
		// Calculate the effect from a manipulator
		public static void CalculateManipulator (PlaygroundParticlesC playgroundParticles, ManipulatorObjectC thisManipulator, int p, float t, float life, Vector3 particlePosition, Vector3 manipulatorPosition, float manipulatorDistance, bool localSpace) {
			if (thisManipulator.enabled && thisManipulator.transform.available && thisManipulator.strength!=0 && thisManipulator.willAffect && thisManipulator.LifetimeFilter(life)) {
				if (!playgroundParticles.onlySourcePositioning) {
					// Attractors
					if (thisManipulator.type==MANIPULATORTYPEC.Attractor) {
						if (thisManipulator.Contains(particlePosition, manipulatorPosition)) {
							playgroundParticles.playgroundCache.velocity[p] = Vector3.Lerp(playgroundParticles.playgroundCache.velocity[p], (manipulatorPosition-particlePosition)*(thisManipulator.strength/manipulatorDistance), t*(thisManipulator.strength/manipulatorDistance)/thisManipulator.strengthSmoothing);
						}
					} else
						
					// Attractors Gravitational
					if (thisManipulator.type==MANIPULATORTYPEC.AttractorGravitational) {
						if (thisManipulator.Contains(particlePosition, manipulatorPosition)) {
							playgroundParticles.playgroundCache.velocity[p] = Vector3.Lerp(playgroundParticles.playgroundCache.velocity[p], (manipulatorPosition-particlePosition)*thisManipulator.strength/manipulatorDistance, t/thisManipulator.strengthSmoothing);
						}
					} else
						
					// Repellents 
					if (thisManipulator.type==MANIPULATORTYPEC.Repellent) {
						if (thisManipulator.Contains(particlePosition, manipulatorPosition)) {
							playgroundParticles.playgroundCache.velocity[p] = Vector3.Lerp(playgroundParticles.playgroundCache.velocity[p], (particlePosition-manipulatorPosition)*(thisManipulator.strength/manipulatorDistance), t*(thisManipulator.strength/manipulatorDistance)/thisManipulator.strengthSmoothing);
						}
					} else

					// Vortex
					if (thisManipulator.type==MANIPULATORTYPEC.Vortex) {
						if (thisManipulator.Contains(particlePosition, manipulatorPosition)) {
							playgroundParticles.playgroundCache.velocity[p] = Vector3.Lerp(playgroundParticles.playgroundCache.velocity[p], ((manipulatorPosition-particlePosition)*thisManipulator.strength/manipulatorDistance)-Vector3.Cross(thisManipulator.transform.up, (manipulatorPosition-particlePosition))*thisManipulator.strength/manipulatorDistance, (t*thisManipulator.strength/manipulatorDistance)/thisManipulator.strengthSmoothing);
						}
					}
				}
				
				// Properties
				if (thisManipulator.type==MANIPULATORTYPEC.Property) {
					PropertyManipulator(playgroundParticles, thisManipulator, thisManipulator.property, p, t, particlePosition, manipulatorPosition, manipulatorDistance, localSpace);
				} else
				
				// Combined
				if (thisManipulator.type==MANIPULATORTYPEC.Combined) {
					for (int i = 0; i<thisManipulator.properties.Count; i++)
						PropertyManipulator(playgroundParticles, thisManipulator, thisManipulator.properties[i], p, t, particlePosition, manipulatorPosition, manipulatorDistance, localSpace);
				}
			}
		}