Ejemplo n.º 1
0
 protected override void LateRun()
 {
     if (_particleSystem == null)
     {
         return;
     }
     lock (locker)
     {
         if (particles == null || particles.Length != _particleSystem.maxParticles)
         {
             particles = new ParticleSystem.Particle[_particleSystem.maxParticles];
             if (particleControllers == null)
             {
                 particleControllers = new ParticleController.Particle[_particleSystem.maxParticles];
             }
             else
             {
                 ParticleController.Particle[] newControllers = new ParticleController.Particle[_particleSystem.maxParticles];
                 for (int i = 0; i < newControllers.Length; i++)
                 {
                     if (i >= particleControllers.Length)
                     {
                         break;
                     }
                     newControllers[i] = particleControllers[i];
                 }
                 particleControllers = newControllers;
             }
         }
         particleCount = _particleSystem.GetParticles(particles);
         bool      isLocal = _particleSystem.simulationSpace == ParticleSystemSimulationSpace.Local;
         Transform particleSystemTransform = _particleSystem.transform;
         for (int i = 0; i < particleCount; i++)
         {
             if (particles[i].remainingLifetime <= 0f)
             {
                 continue;
             }
             if (isLocal)
             {
                 particles[i].position = particleSystemTransform.TransformPoint(particles[i].position);
                 particles[i].velocity = particleSystemTransform.TransformDirection(particles[i].velocity);
             }
             HandleParticle(i);
             if (isLocal)
             {
                 particles[i].position = particleSystemTransform.InverseTransformPoint(particles[i].position);
                 particles[i].velocity = particleSystemTransform.InverseTransformDirection(particles[i].velocity);
             }
         }
         _particleSystem.SetParticles(particles, particleCount);
     }
 }
Ejemplo n.º 2
0
        void HandleParticle(int index)
        {
#if UNITY_5_5_OR_NEWER
            float lifePercent = particles[index].remainingLifetime / particles[index].startLifetime;
#else
            float lifePercent = particles[index].lifetime / particles[index].startLifetime;
#endif
            if (particleControllers[index] == null)
            {
                particleControllers[index] = new ParticleController.Particle();
            }
            if (lifePercent > particleControllers[index].lifePercent)
            {
                OnParticleBorn(index);
            }

            float lifeDelta = particleControllers[index].lifePercent - lifePercent;

            switch (motionType)
            {
            case MotionType.FollowForward: particleControllers[index].splinePercent += lifeDelta * particleControllers[index].speed; break;

            case MotionType.FollowBackward: particleControllers[index].splinePercent -= lifeDelta * particleControllers[index].speed; break;
            }

            if (particleControllers[index].splinePercent < 0f)
            {
                if (wrapMode == Wrap.Loop)
                {
                    particleControllers[index].splinePercent += 1f;
                }
                if (wrapMode == Wrap.Default)
                {
                    particleControllers[index].splinePercent = 0f;
                }
            }
            else if (particleControllers[index].splinePercent > 1f)
            {
                if (wrapMode == Wrap.Loop)
                {
                    particleControllers[index].splinePercent -= 1f;
                }
                if (wrapMode == Wrap.Default)
                {
                    particleControllers[index].splinePercent = 1f;
                }
            }

            if (motionType == MotionType.FollowBackward || motionType == MotionType.FollowForward || motionType == MotionType.None)
            {
                Evaluate(evaluateResult, UnclipPercent(particleControllers[index].splinePercent));
                particles[index].position = evaluateResult.position;
                if (volumetric)
                {
                    Vector3 right  = -Vector3.Cross(evaluateResult.direction, evaluateResult.normal);
                    Vector2 offset = particleControllers[index].startOffset;
                    if (motionType != MotionType.None)
                    {
                        offset = Vector2.Lerp(particleControllers[index].startOffset, particleControllers[index].endOffset, 1f - particleControllers[index].lifePercent);
                    }
                    particles[index].position += right * offset.x * scale.x * evaluateResult.size + evaluateResult.normal * offset.y * scale.y * evaluateResult.size;
                }
                particles[index].velocity = evaluateResult.direction;
            }

            particleControllers[index].lifePercent = lifePercent;
        }
Ejemplo n.º 3
0
        void HandleParticle(int index)
        {
            float lifePercent = particles[index].remainingLifetime / particles[index].startLifetime;

            if (particleControllers[index] == null)
            {
                particleControllers[index] = new ParticleController.Particle();
            }
            if (lifePercent > particleControllers[index].lifePercent)
            {
                OnParticleBorn(index);
            }
            // if (particleControllers[index].lifePercent > lifePercent && lifePercent <= Time.deltaTime) OnParticleDeath(index);


            float lifeDelta = particleControllers[index].lifePercent - lifePercent;

            switch (motionType)
            {
            case MotionType.FollowForward: particleControllers[index].splinePercent += lifeDelta * particleControllers[index].speed; break;

            case MotionType.FollowBackward: particleControllers[index].splinePercent -= lifeDelta * particleControllers[index].speed; break;
            }

            if (particleControllers[index].splinePercent < 0f)
            {
                if (wrapMode == Wrap.Loop)
                {
                    particleControllers[index].splinePercent += 1f;
                }
                if (wrapMode == Wrap.Default)
                {
                    particleControllers[index].splinePercent = 0f;
                }
            }
            else if (particleControllers[index].splinePercent > 1f)
            {
                if (wrapMode == Wrap.Loop)
                {
                    particleControllers[index].splinePercent -= 1f;
                }
                if (wrapMode == Wrap.Default)
                {
                    particleControllers[index].splinePercent = 1f;
                }
            }

            if (motionType == MotionType.FollowBackward || motionType == MotionType.FollowForward || motionType == MotionType.None)
            {
                SplineResult result = Evaluate(DMath.Lerp(clipFrom, clipTo, particleControllers[index].splinePercent));
                particles[index].position = result.position;
                if (volumetric)
                {
                    Vector3 right  = -Vector3.Cross(result.direction, result.normal);
                    Vector2 offset = particleControllers[index].startOffset;
                    if (motionType != MotionType.None)
                    {
                        offset = Vector2.Lerp(particleControllers[index].startOffset, particleControllers[index].endOffset, 1f - particleControllers[index].lifePercent);
                    }
                    particles[index].position += right * offset.x * scale.x * result.size + result.normal * offset.y * scale.y * result.size;
                }
                particles[index].velocity = result.direction;
            }

            particleControllers[index].lifePercent = lifePercent;
        }