Esempio n. 1
0
        void UpdateParticles(FlexContainer.ParticleData _particleData)
        {
            if (handle && m_indices != null && m_indices.Length > 0)
            {
                float dT = Application.isPlaying ? Time.fixedDeltaTime : 0;

                int newCount = FlexUtils.UpdateSourceParticles(ref m_indices[0], ref m_ages[0], m_count, _particleData.particleData.particles, dT, massScale);

                if (newCount != m_count)
                {
                    m_currentContainer.FreeParticles(m_indices, newCount, m_count - newCount);
                    m_count = newCount;
                }

                if (m_isActive && m_startSpeed > 0)
                {
                    m_spawnTime += dT;
                    while (m_spawnTime > 0)
                    {
                        int spawnCount = Mathf.Min(m_asset.nozzleCount, m_asset.maxParticles - m_count);
                        if (spawnCount > 0)
                        {
                            newCount += m_currentContainer.AllocParticles(m_indices, m_count, spawnCount);
                            for (int i = m_count; i < newCount; ++i)
                            {
                                int index  = m_indices[i];
                                int nozzle = i - m_count;
                                _particleData.SetPhase(index, m_phase);
                                Vector3 direction = transform.TransformDirection(m_asset.nozzleDirections[nozzle]);
                                Vector3 velocity  = direction * m_startSpeed;
                                _particleData.SetVelocity(index, velocity);
                                Vector3 position = transform.TransformPoint(m_asset.nozzlePositions[nozzle]);
                                position -= velocity * (2.0f * dT - m_spawnTime);
                                Vector4 particle = position; particle.w = 0.000001f;//1.0f / massScale;//
                                _particleData.SetParticle(index, particle);
                                _particleData.SetRestParticle(index, Vector3.zero);
                                m_ages[i] = m_lifeTime;
                            }
                            m_count = newCount;
                        }
                        float dist = /*fluid ? m_currentContainer.fluidRest :*/ m_currentContainer.solidRest;
                        m_spawnTime -= dist / m_startSpeed;
                    }
                }

                SetIndices(m_indices, m_count);
            }
        }