public void ResetParams()
 {
     emitParams.ResetAngularVelocity();
     emitParams.ResetAxisOfRotation();
     emitParams.ResetPosition();
     emitParams.ResetRandomSeed();
     emitParams.ResetRotation();
     emitParams.ResetStartColor();
     emitParams.ResetStartLifetime();
     emitParams.ResetStartSize();
     emitParams.ResetVelocity();
 }
Пример #2
0
    private void Update()
    {
        #region Length Psys
        // GetParticles is allocation free because we reuse the m_Particles buffer between updates
        m_LengthPSys.GetParticles(m_LengthParticles);

        // Change only the particles that are alive
        for (int i = 0; i < m_LengthParticleCount; i++)
        {
            float norm  = (float)i / (float)m_LengthParticleCount;
            float rand  = norm * (m_Count - 1);
            int   index = (int)Mathf.Floor(rand);
            float lerp  = rand - index;

            Vector3 pos;
            if (index == 0)
            {
                pos = Vector3.Lerp(transform.position, m_Followers[0].transform.position, lerp);
            }
            else
            {
                pos = Vector3.Lerp(m_Followers[index - 1].transform.position, m_Followers[index].transform.position, lerp);
            }

            m_LengthParticles[i].position = pos;

            float offsetSize = (((Mathf.Sin((Time.time + i) * .3f) + 1) / 2f) * .95f);
            m_LengthParticles[i].size = .02f + m_LengthSizeCurve.Evaluate(norm) * offsetSize;
        }

        // Apply the particle changes to the particle system
        m_LengthPSys.SetParticles(m_LengthParticles, m_LengthParticleCount);
        #endregion

        #region Emit Psys
        float speed = 0;
        for (int i = 0; i < m_Followers.Length; i++)
        {
            speed += m_Followers[i]._CurrentSpeed;
        }

        speed /= m_MaxSpeed;

        int emitCount = (int)m_EmitCurve.Evaluate(speed);

        for (int i = 0; i < emitCount; i++)
        {
            float rand  = Random.Range(0f, (float)m_Count - 1);
            int   index = (int)Mathf.Floor(rand);
            float lerp  = rand - index;

            Vector3 emitPos = Vector3.Lerp(m_Followers[index].transform.position, m_Followers[index + 1].transform.position, lerp);
            m_EmitParams.position  = emitPos;
            m_EmitParams.startSize = .07f * (1 - (rand / (float)m_Count)) * (m_Followers[index]._CurrentDirection.magnitude * m_SizeByVel);
            m_EmitParams.velocity  = m_Followers[index]._CurrentDirection * m_InheritVelLrg;
            m_FollowPSys.Emit(m_EmitParams, 1);

            if (lerp < .5f)
            {
                m_EmitParams.ResetStartSize();
                m_EmitParams.velocity = m_Followers[index]._CurrentDirection * m_InheritVelSmall;
                m_FollowPSys2.Emit(m_EmitParams, 1);
            }
        }
        #endregion
    }