Esempio n. 1
0
        /// <summary>
        /// 绘制粒子公告板
        /// </summary>
        /// <param name="particle">要绘制的粒子</param>
        /// <param name="vh">顶点辅助器</param>
        private void DrawParticleBillboard(ParticleSystem.Particle particle, VertexHelper vh)
        {
            Vector3    center   = particle.position;
            Quaternion rotation = Quaternion.Euler(particle.rotation3D);

            if (ParticleSystem.main.simulationSpace == ParticleSystemSimulationSpace.World)
            {
                center = rectTransform.InverseTransformPoint(center);
            }

            float timeAlive       = particle.startLifetime - particle.remainingLifetime;
            float globalTimeAlive = timeAlive / particle.startLifetime;

            Vector3 size3D = particle.GetCurrentSize3D(ParticleSystem);

            Vector3 leftTop = Vector3.zero, rightTop = Vector3.zero, rightBottom = Vector3.zero, leftBottom = Vector3.zero;

            if (m_RenderMode == UiParticleRenderMode.StreachedBillboard)
            {
                GetStrechedBillboardsSizeAndRotation(particle, globalTimeAlive, ref size3D, out rotation);
                leftTop     = new Vector3(-size3D.x * 0.5f, 0);
                rightTop    = new Vector3(-size3D.x * 0.5f, size3D.y);
                rightBottom = new Vector3(size3D.x * 0.5f, size3D.y);
                leftBottom  = new Vector3(size3D.x * 0.5f, 0);
            }
            else
            {
                leftTop     = new Vector3(-size3D.x * 0.5f, size3D.y * 0.5f);
                rightTop    = new Vector3(size3D.x * 0.5f, size3D.y * 0.5f);
                rightBottom = new Vector3(size3D.x * 0.5f, -size3D.y * 0.5f);
                leftBottom  = new Vector3(-size3D.x * 0.5f, -size3D.y * 0.5f);
            }

            leftTop     = rotation * leftTop + center;
            rightTop    = rotation * rightTop + center;
            rightBottom = rotation * rightBottom + center;
            leftBottom  = rotation * leftBottom + center;

            Color32 color32 = particle.GetCurrentColor(ParticleSystem);
            int     i       = vh.currentVertCount;

            Vector2[] uvs = new Vector2[4];

            if (!ParticleSystem.textureSheetAnimation.enabled)
            {
                EvaluateQuadUVs(uvs);
            }
            else
            {
                EvaluateTexturesheetUVs(particle, timeAlive, uvs);
            }

            vh.AddVert(leftBottom, color32, uvs[0]);
            vh.AddVert(leftTop, color32, uvs[1]);
            vh.AddVert(rightTop, color32, uvs[2]);
            vh.AddVert(rightBottom, color32, uvs[3]);

            vh.AddTriangle(i, i + 1, i + 2);
            vh.AddTriangle(i + 2, i + 3, i);
        }
Esempio n. 2
0
    void LateUpdate()
    {
        //获取粒子数据
        numParticlesAlive = mParticleSystem.GetParticles(particles);

        //两个粒子的距离小于MinDist就连线
        for (int i = 0; i < numParticlesAlive; i++)
        {
            for (int j = i + 1; j < numParticlesAlive; j++)
            {
                //粒子直接距离的平方
                float SqrDis = (particles[j].position - particles[i].position).sqrMagnitude;

                if (SqrDis < MinDist * MinDist)
                {
                    ParticleSystem.Particle particle     = particles[j];
                    ParticleSystem.Particle cur_particle = particles[i];
                    //获取粒子的颜色
                    Color sColor = cur_particle.GetCurrentColor(mParticleSystem);
                    Color eColor = particle.GetCurrentColor(mParticleSystem);
                    //计算宽度
                    //float width = LineWidth*LineWidthOverLifetime.Evaluate(cur_particle.remainingLifetime/cur_particle.startLifetime);
                    //绘制线
                    DrawLine(cur_particle.position, particle.position, sColor, eColor, LineWidth);
                }
            }
        }

        mParticleSystem.SetParticles(particles, numParticlesAlive);
        for (int i = index; i < linePool.Count; i++)
        {
            linePool[i].gameObject.SetActive(false);
        }
        index = 0;
    }
Esempio n. 3
0
        private void DrawParticleBillboard(
            ParticleSystem.Particle particle,
            VertexHelper vh,
            ParticleSystem.MinMaxCurve frameOverTime,
            ParticleSystem.MinMaxCurve velocityOverTimeX,
            ParticleSystem.MinMaxCurve velocityOverTimeY,
            ParticleSystem.MinMaxCurve velocityOverTimeZ,
            bool isWorldSimulationSpace,
            ParticleSystem.TextureSheetAnimationModule textureSheetAnimationModule)
        {
            var center   = particle.position;
            var rotation = Quaternion.Euler(particle.rotation3D);

            if (isWorldSimulationSpace)
            {
                center = rectTransform.InverseTransformPoint(center);
            }

            float timeAlive       = particle.startLifetime - particle.remainingLifetime;
            float globalTimeAlive = timeAlive / particle.startLifetime;

            Vector3 size3D = particle.GetCurrentSize3D(ParticleSystem);

            if (m_RenderMode == UiParticleRenderMode.StreachedBillboard)
            {
                GetStrechedBillboardsSizeAndRotation(particle, globalTimeAlive, ref size3D, out rotation,
                                                     velocityOverTimeX, velocityOverTimeY, velocityOverTimeZ);
            }

            var leftTop     = new Vector3(-size3D.x * 0.5f, size3D.y * 0.5f);
            var rightTop    = new Vector3(size3D.x * 0.5f, size3D.y * 0.5f);
            var rightBottom = new Vector3(size3D.x * 0.5f, -size3D.y * 0.5f);
            var leftBottom  = new Vector3(-size3D.x * 0.5f, -size3D.y * 0.5f);


            leftTop     = rotation * leftTop + center;
            rightTop    = rotation * rightTop + center;
            rightBottom = rotation * rightBottom + center;
            leftBottom  = rotation * leftBottom + center;

            Color32 color32 = particle.GetCurrentColor(ParticleSystem);
            var     i       = vh.currentVertCount;

            Vector2 uv0;
            Vector2 uv1;
            Vector2 uv2;
            Vector2 uv3;

            CalculateUvs(particle, frameOverTime, textureSheetAnimationModule, timeAlive, out uv0, out uv1, out uv2,
                         out uv3);

            vh.AddVert(leftBottom, color32, uv0);
            vh.AddVert(leftTop, color32, uv1);
            vh.AddVert(rightTop, color32, uv2);
            vh.AddVert(rightBottom, color32, uv3);

            vh.AddTriangle(i, i + 1, i + 2);
            vh.AddTriangle(i + 2, i + 3, i);
        }
Esempio n. 4
0
        private void DrawParticleMesh(
            ParticleSystem.Particle particle,
            VertexHelper vh,
            ParticleSystem.MinMaxCurve frameOverTime,
            bool isWorldSimulationSpace,
            ParticleSystem.TextureSheetAnimationModule textureSheetAnimationModule, Vector3[] verts, int[] triangles,
            Vector2[] uvs)
        {
            var center   = particle.position;
            var rotation = Quaternion.Euler(particle.rotation3D);

            if (isWorldSimulationSpace)
            {
                center = rectTransform.InverseTransformPoint(center);
            }

            float timeAlive       = particle.startLifetime - particle.remainingLifetime;
            float globalTimeAlive = timeAlive / particle.startLifetime;

            Vector3 size3D  = particle.GetCurrentSize3D(ParticleSystem);
            Color32 color32 = particle.GetCurrentColor(ParticleSystem);

            Vector2 uv0;
            Vector2 uv1;
            Vector2 uv2;
            Vector2 uv3;

            CalculateUvs(particle, frameOverTime, textureSheetAnimationModule, timeAlive, out uv0, out uv1, out uv2,
                         out uv3);

            var currentVertCount = vh.currentVertCount;

            for (int j = 0; j < verts.Length; j++)
            {
                Vector3 pos = verts[j];
                pos.x *= size3D.x;
                pos.y *= size3D.y;
                pos.z *= size3D.z;
                pos    = rotation * pos + center;

                var uvXpercent = uvs[j].x;
                var uvYpercent = uvs[j].y;

                var newUvx = Mathf.Lerp(uv0.x, uv2.x, uvXpercent);
                var newUvy = Mathf.Lerp(uv0.y, uv2.y, uvYpercent);

                vh.AddVert(pos, color32, new Vector2(newUvx, newUvy));
            }

            for (int i = 0; i < triangles.Length; i += 3)
            {
                vh.AddTriangle(currentVertCount + triangles[i],
                               currentVertCount + triangles[i + 1],
                               currentVertCount + triangles[i + 2]);
            }
        }
Esempio n. 5
0
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        vh.Clear();

        int numberOfParticles = m_particleSystem.GetParticles(m_particleArray);

        if (m_particleArray == null || m_particleArray.Length <= 0)
        {
            return;
        }

        for (int i = 0; i < numberOfParticles; i++)
        {
            ParticleSystem.Particle particle = m_particleArray[i];
            Vector2[] particleVertices       = new[] { Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero };
            float     size         = particle.GetCurrentSize(m_particleSystem) * m_sizeMultiplier;
            Vector3   partPosition = particle.position * m_sizeMultiplier;
            Vector2   partCorner1  = (Vector2)(partPosition) + new Vector2(-(size / 2), -(size / 2));
            Vector2   partCorner2  = (Vector2)(partPosition) + new Vector2((size / 2), (size / 2));

            particleVertices[0] = new Vector2(partCorner1.x, partCorner1.y);
            particleVertices[1] = new Vector2(partCorner1.x, partCorner2.y);
            particleVertices[2] = new Vector2(partCorner2.x, partCorner2.y);
            particleVertices[3] = new Vector2(partCorner2.x, partCorner1.y);

            particleVertices[0] = CanvasParticleHelper.RotatePointAroundPivot(particleVertices[0], partPosition, new Vector3(0, 0, -particle.rotation));
            particleVertices[1] = CanvasParticleHelper.RotatePointAroundPivot(particleVertices[1], partPosition, new Vector3(0, 0, -particle.rotation));
            particleVertices[2] = CanvasParticleHelper.RotatePointAroundPivot(particleVertices[2], partPosition, new Vector3(0, 0, -particle.rotation));
            particleVertices[3] = CanvasParticleHelper.RotatePointAroundPivot(particleVertices[3], partPosition, new Vector3(0, 0, -particle.rotation));

            Vector2[] particleUV = new Vector2[4];
            if (m_AtlasUVs != null && m_AtlasUVs.Count > 1)
            {
                int particleFrame = Mathf.FloorToInt((((particle.startLifetime - particle.remainingLifetime)) * m_AtlasUVs.Count) / particle.startLifetime);

                Vector4 textUV = m_AtlasUVs[particleFrame];
                particleUV[0] = new Vector2(textUV.x, textUV.w);
                particleUV[1] = new Vector2(textUV.x, textUV.y);
                particleUV[2] = new Vector2(textUV.z, textUV.y);
                particleUV[3] = new Vector2(textUV.z, textUV.w);
            }
            else
            {
                particleUV[0] = new Vector2(0, 1);
                particleUV[1] = Vector2.zero;
                particleUV[2] = new Vector2(1, 0);
                particleUV[3] = new Vector2(1, 1);
            }


            SetMesh(vh, particleVertices, particleUV, particle.GetCurrentColor(m_particleSystem));
        }
    }
Esempio n. 6
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            vh.Clear();
            if (!base.gameObject.activeInHierarchy)
            {
                return;
            }
            int particles = _particleSystem.GetParticles(_particles);

            for (int i = 0; i < particles; i++)
            {
                ParticleSystem.Particle particle = _particles[i];
                Vector2 vector       = ((_particleSystem.simulationSpace != 0) ? _transform.InverseTransformPoint(particle.position) : particle.position);
                float   num          = (0f - particle.rotation) * ((float)Math.PI / 180f);
                float   f            = num + (float)Math.PI / 2f;
                Color32 currentColor = particle.GetCurrentColor(_particleSystem);
                float   num2         = particle.GetCurrentSize(_particleSystem) * 0.5f;
                if (_particleSystem.scalingMode == ParticleSystemScalingMode.Shape)
                {
                    vector /= base.canvas.scaleFactor;
                }
                Vector4 uv = _uv;
                if (_textureSheetAnimation.enabled)
                {
                    float num3 = 1f - particle.remainingLifetime / particle.startLifetime;
                    num3 = Mathf.Repeat(num3 * (float)_textureSheetAnimation.cycleCount, 1f);
                    int num4 = 0;
                    switch (_textureSheetAnimation.animation)
                    {
                    case ParticleSystemAnimationType.WholeSheet:
                        num4 = Mathf.FloorToInt(num3 * (float)_textureSheetAnimationFrames);
                        break;

                    case ParticleSystemAnimationType.SingleRow:
                    {
                        num4 = Mathf.FloorToInt(num3 * (float)_textureSheetAnimation.numTilesX);
                        int rowIndex = _textureSheetAnimation.rowIndex;
                        num4 += rowIndex * _textureSheetAnimation.numTilesX;
                        break;
                    }
                    }
                    num4 %= _textureSheetAnimationFrames;
                    uv.x  = (float)(num4 % _textureSheetAnimation.numTilesX) * _textureSheedAnimationFrameSize.x;
                    uv.y  = (float)Mathf.FloorToInt(num4 / _textureSheetAnimation.numTilesX) * _textureSheedAnimationFrameSize.y;
                    uv.z  = uv.x + _textureSheedAnimationFrameSize.x;
                    uv.w  = uv.y + _textureSheedAnimationFrameSize.y;
                }
                ref UIVertex reference = ref _quad[0];
                reference      = UIVertex.simpleVert;
                _quad[0].color = currentColor;
                _quad[0].uv0   = new Vector2(uv.x, uv.y);
                ref UIVertex reference2 = ref _quad[1];
Esempio n. 7
0
        private Gradient ParticleGradientColor(ParticleSystem.Particle p1, ParticleSystem.Particle p2)
        {
            Gradient gradient = new Gradient();
            float    alpha    = 1f;
            Color32  p1_color = p1.GetCurrentColor(particleSystem);
            Color32  p2_color = p2.GetCurrentColor(particleSystem);

            gradient.SetKeys(
                new GradientColorKey[] { new GradientColorKey(p1_color, 0.0f), new GradientColorKey(p2_color, 1.0f) },
                new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) }
                );
            return(gradient);
        }
                // ...

                void LateUpdate()
                {
                    ParticleSystem.Particle[] particles =
                        new ParticleSystem.Particle[ps.particleCount];

                    int numOfParticles = ps.GetParticles(particles);

                    if (lights.Count != numOfParticles)
                    {
                        for (int i = 0; i < lights.Count; i++)
                        {
                            Destroy(lights[i].gameObject);
                        }

                        lights.Clear();

                        for (int i = 0; i < numOfParticles; i++)
                        {
                            GameObject go = Instantiate(template, transform) as GameObject;
                            go.name = "- " + (i + 1).ToString();

                            lights.Add(go.AddComponent <Light>());
                        }
                    }

                    ParticleSystem.MainModule m = ps.main;
                    bool worldSpace             = m.simulationSpace == ParticleSystemSimulationSpace.World;

                    for (int i = 0; i < numOfParticles; i++)
                    {
                        ParticleSystem.Particle p = particles[i];

                        Light light = lights[i];

                        //light.type = type;

                        //if (type == LightType.Spot)
                        //{
                        //    light.transform.rotation = Quaternion.Euler(p.rotation3D);
                        //}

                        light.range = p.GetCurrentSize(ps) * scale;
                        light.color = Color.Lerp(colour, p.GetCurrentColor(ps), colourFromParticle);

                        light.intensity = intensity;

                        light.shadows = shadows;

                        light.transform.position = worldSpace ? p.position : ps.transform.TransformPoint(p.position);
                    }
                }
    protected void ExportPointCloud()
    {
        StreamWriter sw = new StreamWriter("C:\\Users\\ISAACS\\Documents\\ISAACSRadViz\\ColoredPointCloud.off", false);

        sw.WriteLine("COFF");
        sw.WriteLine(particle_count + " " + 0 + " " + 0);

        for (int i = 0; i < particle_count; i++)
        {
            ParticleSystem.Particle particle = particles[i];
            Vector3 pos = particle.position;
            Color32 col = particle.GetCurrentColor(cloud);

            sw.WriteLine(pos.x + " " + pos.y + " " + pos.z + " " + col.r + " " + col.g + " " + col.b + " " + col.a);
            sw.Close();
        }
    }
Esempio n. 10
0
        private void DrawParticleMesh(ParticleSystem.Particle particle, VertexHelper vh,
                                      ParticleSystem.MinMaxCurve frameOverTime, bool isWorldSimulationSpace,
                                      ParticleSystem.TextureSheetAnimationModule textureSheetAnimationModule,
                                      Vector3[] verts, int[] triangles, Vector2[] uvs)
        {
            var center   = particle.position;
            var rotation = Quaternion.Euler(particle.rotation3D);

            if (isWorldSimulationSpace)
            {
                center = rectTransform.InverseTransformPoint(center);
            }

            float timeAlive = particle.startLifetime - particle.remainingLifetime;

            Vector3 size3D = particle.GetCurrentSize3D(Particle);

            Color32 color32 = particle.GetCurrentColor(Particle);

            CalculateUvs(particle, frameOverTime, textureSheetAnimationModule, timeAlive, out uv4[0], out uv4[1], out uv4[2], out uv4[3]);

            int count = vh.currentVertCount;

            Vector3 position;

            Vector2 point = new Vector2();

            for (int j = 0; j < verts.Length; j++)
            {
                position    = verts[j];
                position.x *= size3D.x;
                position.y *= size3D.y;
                position.z *= size3D.z;
                position    = rotation * position + center;

                point.x = Mathf.Lerp(uv4[0].x, uv4[2].x, uvs[j].x);
                point.y = Mathf.Lerp(uv4[0].y, uv4[2].y, uvs[j].y);

                vh.AddVert(position, color32, point);
            }

            for (int i = 0; i < triangles.Length; i += 3)
            {
                vh.AddTriangle(count + triangles[i], count + triangles[i + 1], count + triangles[i + 2]);
            }
        }
Esempio n. 11
0
        private void DrawParticleBillboard(ParticleSystem.Particle particle, VertexHelper vh)
        {
            var center = particle.position;

            var rotation = Quaternion.Euler(particle.rotation3D);

            if (ParticleSystem.main.simulationSpace == ParticleSystemSimulationSpace.World)
            {
                center = rectTransform.InverseTransformPoint(center);
            }

            float timeAlive       = particle.startLifetime - particle.remainingLifetime;
            float globalTimeAlive = timeAlive / particle.startLifetime;

            Vector3 size3D = Vector3.zero;

                    #if UNITY_5_4_OR_NEWER
            size3D = particle.GetCurrentSize3D(ParticleSystem);
            #else
            var size = particle.GetCurrentSize(ParticleSystem);
            size3D = new Vector3(size, size, size);
            #endif

            if (m_RenderMode == UiParticleRenderMode.StreachedBillboard)
            {
                GetStrechedBillboardsSizeAndRotation(particle, globalTimeAlive, ref size3D, ref rotation);
            }


            var leftTop     = new Vector3(-size3D.x * 0.5f, size3D.y * 0.5f);
            var rightTop    = new Vector3(size3D.x * 0.5f, size3D.y * 0.5f);
            var rightBottom = new Vector3(size3D.x * 0.5f, -size3D.y * 0.5f);
            var leftBottom  = new Vector3(-size3D.x * 0.5f, -size3D.y * 0.5f);


            leftTop     = rotation * leftTop + center;
            rightTop    = rotation * rightTop + center;
            rightBottom = rotation * rightBottom + center;
            leftBottom  = rotation * leftBottom + center;

            Color32 color32 = particle.GetCurrentColor(ParticleSystem);
            var     i       = vh.currentVertCount;

            Vector2[] uvs = new Vector2[4];

            if (!ParticleSystem.textureSheetAnimation.enabled)
            {
                uvs [0] = new Vector2(0f, 0f);
                uvs [1] = new Vector2(0f, 1f);
                uvs [2] = new Vector2(1f, 1f);
                uvs [3] = new Vector2(1f, 0f);
            }
            else
            {
                var textureAnimator = ParticleSystem.textureSheetAnimation;

                float lifeTimePerCycle = particle.startLifetime / textureAnimator.cycleCount;
                float timePerCycle     = timeAlive % lifeTimePerCycle;

                float timeAliveAnim01 = timePerCycle / lifeTimePerCycle;;                 // in percents


                float frame01;
                var   totalFramesCount = textureAnimator.numTilesY * textureAnimator.numTilesX;
                #if UNITY_5_4_OR_NEWER
                frame01 = textureAnimator.frameOverTime.Evaluate(timeAliveAnim01);
                #else
                frame01 = m_FrameOverLifetime.Evaluate(timeAliveAnim01, (int)particle.randomSeed, 0, totalFramesCount - 1);
                #endif



                var frame = 0f;
                switch (textureAnimator.animation)
                {
                case ParticleSystemAnimationType.WholeSheet:
                {
                    frame = Mathf.Clamp(Mathf.Floor(frame01 * totalFramesCount), 0, totalFramesCount - 1);
                    break;
                }

                case ParticleSystemAnimationType.SingleRow:
                {
                    frame = Mathf.Clamp(Mathf.Floor(frame01 * textureAnimator.numTilesX), 0, textureAnimator.numTilesX - 1);
                    int row = textureAnimator.rowIndex;
                    if (textureAnimator.useRandomRow)
                    {
                        Random.InitState((int)particle.randomSeed);
                        row = Random.Range(0, textureAnimator.numTilesY);
                    }
                    frame += row * textureAnimator.numTilesX;
                    break;
                }
                }


                int x = (int)frame % textureAnimator.numTilesX;
                int y = (int)frame / textureAnimator.numTilesY;


                var xDelta = 1f / textureAnimator.numTilesX;
                var yDelta = 1f / textureAnimator.numTilesY;
                y = textureAnimator.numTilesY - 1 - y;
                var sX = x * xDelta;
                var sY = y * yDelta;
                var eX = sX + xDelta;
                var eY = sY + yDelta;

                uvs [0] = new Vector2(sX, sY);
                uvs [1] = new Vector2(sX, eY);
                uvs [2] = new Vector2(eX, eY);
                uvs [3] = new Vector2(eX, sY);
            }

            vh.AddVert(leftBottom, color32, uvs [0]);
            vh.AddVert(leftTop, color32, uvs [1]);
            vh.AddVert(rightTop, color32, uvs [2]);
            vh.AddVert(rightBottom, color32, uvs [3]);

            vh.AddTriangle(i, i + 1, i + 2);
            vh.AddTriangle(i + 2, i + 3, i);
        }
Esempio n. 12
0
    // Update is called once per frame
    void Update()
    {
        ParticleSystem.Particle[] particles = new ParticleSystem.Particle[ps.particleCount];
        ps.GetParticles(particles);

        for (int i = 0; i < ps.main.maxParticles; i++)
        {
            if (i < ps.particleCount)
            {
                Vector3 particleWorldPosition;
                ParticleSystem.Particle p = particles[i];

                if (ps.main.simulationSpace == ParticleSystemSimulationSpace.Local)
                {
                    particleWorldPosition = transform.TransformPoint(p.position);
                }
                else if (ps.main.simulationSpace == ParticleSystemSimulationSpace.Custom)
                {
                    particleWorldPosition = ps.main.customSimulationSpace.TransformPoint(p.position);
                }
                else
                {
                    particleWorldPosition = p.position;
                }
                // update tube vertex locations
                //init list of vertexes that form a trail, if it does not exist
                if (i > tubes.Count - 1)
                {
                    tubes.Add(new List <TubeRenderer.TubeVertex>());
                    tubes[i].Add(new TubeRenderer.TubeVertex(particleWorldPosition, tubeWidth, p.GetCurrentColor(ps)));
                }
                //prevent old and new particles joining together on respawn
                else if ((p.startLifetime - p.remainingLifetime < 0.2f))
                {
                    tubes[i].RemoveRange(0, tubes[i].Count);
                    tubes[i].Add(new TubeRenderer.TubeVertex(particleWorldPosition, tubeWidth, p.GetCurrentColor(ps)));
                }
                else
                {
                    if (Vector3.Distance(particleWorldPosition, tubes[i][tubes[i].Count - 1].point) > 0.1f)
                    {
                        // remove head and add new point
                        if (tubes[i].Count > tubeSteps)
                        {
                            tubes[i].RemoveAt(0);
                        }
                        tubes[i].Add(new TubeRenderer.TubeVertex(particleWorldPosition, tubeWidth, p.GetCurrentColor(ps)));
                    }
                }
            }
            else
            {
                // particle does not exist yet (since current particles may be less than max particles)
                if (i <= tubes.Count - 1)
                {
                    tubes[i].RemoveRange(0, tubes[i].Count);
                }
            }
        }
        tr.lines = tubes;
    }
Esempio n. 13
0
    protected override void OnPopulateMesh(VertexHelper vh)
    {
                #if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            if (!Initialize())
            {
                return;
            }
        }
                #endif

        // prepare vertices
        vh.Clear();

        if (!gameObject.activeInHierarchy)
        {
            return;
        }

        // iterate through current particles
        int count = _particleSystem.GetParticles(_particles);

        for (int i = 0; i < count; ++i)
        {
            ParticleSystem.Particle particle = _particles[i];

            // get particle properties
            Vector2 position   = (_particleSystem.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position));
            float   rotation   = -particle.rotation * Mathf.Deg2Rad;
            float   rotation90 = rotation + Mathf.PI / 2;
            Color32 color      = particle.GetCurrentColor(_particleSystem);
            float   size       = particle.GetCurrentSize(_particleSystem) * 0.5f;

            // apply scale
            if (_particleSystem.scalingMode == ParticleSystemScalingMode.Shape)
            {
                position /= canvas.scaleFactor;
            }

            // apply texture sheet animation
            Vector4 particleUV = _uv;
            if (_textureSheetAnimation.enabled)
            {
                float frameProgress = 1 - (particle.remainingLifetime / particle.startLifetime);
                //                float frameProgress = textureSheetAnimation.frameOverTime.curveMin.Evaluate(1 - (particle.lifetime / particle.startLifetime)); // TODO - once Unity allows MinMaxCurve reading
                frameProgress = Mathf.Repeat(frameProgress * _textureSheetAnimation.cycleCount, 1);
                int frame = 0;

                switch (_textureSheetAnimation.animation)
                {
                case ParticleSystemAnimationType.WholeSheet:
                    frame = Mathf.FloorToInt(frameProgress * _textureSheetAnimationFrames);
                    break;

                case ParticleSystemAnimationType.SingleRow:
                    frame = Mathf.FloorToInt(frameProgress * _textureSheetAnimation.numTilesX);

                    int row = _textureSheetAnimation.rowIndex;
                    //                    if (textureSheetAnimation.useRandomRow) { // FIXME - is this handled internally by rowIndex?
                    //                        row = Random.Range(0, textureSheetAnimation.numTilesY, using: particle.randomSeed);
                    //                    }
                    frame += row * _textureSheetAnimation.numTilesX;
                    break;
                }

                frame %= _textureSheetAnimationFrames;

                particleUV.x = (frame % _textureSheetAnimation.numTilesX) * _textureSheedAnimationFrameSize.x;
                particleUV.y = Mathf.FloorToInt(frame / _textureSheetAnimation.numTilesX) * _textureSheedAnimationFrameSize.y;
                particleUV.z = particleUV.x + _textureSheedAnimationFrameSize.x;
                particleUV.w = particleUV.y + _textureSheedAnimationFrameSize.y;
            }

            _quad[0]       = UIVertex.simpleVert;
            _quad[0].color = color;
            _quad[0].uv0   = new Vector2(particleUV.x, particleUV.y);

            _quad[1]       = UIVertex.simpleVert;
            _quad[1].color = color;
            _quad[1].uv0   = new Vector2(particleUV.x, particleUV.w);

            _quad[2]       = UIVertex.simpleVert;
            _quad[2].color = color;
            _quad[2].uv0   = new Vector2(particleUV.z, particleUV.w);

            _quad[3]       = UIVertex.simpleVert;
            _quad[3].color = color;
            _quad[3].uv0   = new Vector2(particleUV.z, particleUV.y);

            if (rotation == 0)
            {
                // no rotation
                Vector2 corner1 = new Vector2(position.x - size, position.y - size);
                Vector2 corner2 = new Vector2(position.x + size, position.y + size);

                _quad[0].position = new Vector2(corner1.x, corner1.y);
                _quad[1].position = new Vector2(corner1.x, corner2.y);
                _quad[2].position = new Vector2(corner2.x, corner2.y);
                _quad[3].position = new Vector2(corner2.x, corner1.y);
            }
            else
            {
                // apply rotation
                Vector2 right = new Vector2(Mathf.Cos(rotation), Mathf.Sin(rotation)) * size;
                Vector2 up    = new Vector2(Mathf.Cos(rotation90), Mathf.Sin(rotation90)) * size;

                _quad[0].position = position - right - up;
                _quad[1].position = position - right + up;
                _quad[2].position = position + right + up;
                _quad[3].position = position + right - up;
            }

            vh.AddUIVertexQuad(_quad);
        }
    }
Esempio n. 14
0
    private void AddParticleBillboard(int particleIndex, bool isWorldSimulationSpace)
    {
        ParticleSystem.Particle particle = particles[particleIndex];

        Color32 color32 = particle.GetCurrentColor(pfx);

        // compute texture coordinates

        Profiler.BeginSample("compute texture coordinates");

        Vector2 coord0, coord1, coord2, coord3;

        if (textureSheetAnimation.enabled)
        {
            CalculateAnimatedUvs(particle, textureSheetAnimation, out coord0, out coord1, out coord2, out coord3);
        }
        else
        {
            CalculateUvs(out coord0, out coord1, out coord2, out coord3);
        }


        Profiler.EndSample();

        // compute vertex positions

        Profiler.BeginSample("compute vertex positions");

        Vector3   size3D        = particle.GetCurrentSize3D(pfx);
        Matrix4x4 toLocalMatrix = rectTransform.worldToLocalMatrix;

        GetPositions(particle, isWorldSimulationSpace, size3D, toLocalMatrix,
                     out Vector3 leftBottom, out Vector3 leftTop, out Vector3 rightTop, out Vector3 rightBottom);

        Profiler.EndSample();

        Profiler.BeginSample("set mesh data");

        // set vertices

        void AddVertex(int index, Vector3 position, Color32 color, Vector2 uv0)
        {
            vertices[index] = position;
            colors[index]   = color;
            coords[index]   = uv0;
        }

        int vertexIndex = particleIndex * 4;
        int v0          = vertexIndex;
        int v1          = vertexIndex + 1;
        int v2          = vertexIndex + 2;
        int v3          = vertexIndex + 3;

        AddVertex(v0, leftBottom, color32, coord0);
        AddVertex(v1, leftTop, color32, coord1);
        AddVertex(v2, rightTop, color32, coord2);
        AddVertex(v3, rightBottom, color32, coord3);

        // set triangles indices

        int triangleIndex = particleIndex * 6;

        triangles[triangleIndex]     = v0;
        triangles[triangleIndex + 1] = v1;
        triangles[triangleIndex + 2] = v2;

        triangles[triangleIndex + 3] = v2;
        triangles[triangleIndex + 4] = v3;
        triangles[triangleIndex + 5] = v0;

        Profiler.EndSample();
    }
        public void ReconstructParticleSystem()
        {
            foreach (ParticleCollider curParticleCollider in particleColliders)
            {
                GameObject curGO = curParticleCollider.gameObject;
                ParticleSystem.Particle curParticle = curParticleCollider.Particle;

                float   rotationCorrection = 1f;
                Vector3 pivot = particleSystemRenderer.pivot;
                Vector3 size  = curParticle.GetCurrentSize3D(particleSys);

                // Get hierarchy scale
                Vector3 transformScale = particleSys.transform.localScale;

                // Apply position
                switch (particleSys.main.simulationSpace)
                {
                case ParticleSystemSimulationSpace.Local:
                    curGO.transform.SetParent(particleSys.gameObject.transform);
                    curGO.transform.localPosition = curParticle.position;

                    pivot = Vector3.Scale(pivot, transformScale);
                    break;

                case ParticleSystemSimulationSpace.World:
                    curGO.transform.SetParent(null);
                    curGO.transform.position = curParticle.position;

                    size = Vector3.Scale(size, transformScale);
                    break;
                }

                switch (particleSystemRenderer.renderMode)
                {
                case ParticleSystemRenderMode.Billboard:
                    // Billboard to camera
                    curGO.transform.LookAt(curGO.transform.position + cam.transform.rotation * Vector3.forward, cam.transform.rotation * Vector3.up);

                    rotationCorrection = -1f;
                    break;

                case ParticleSystemRenderMode.Mesh:
                    curGO.transform.rotation = Quaternion.identity;

                    // For mesh pivots, Z is Y and Y is Z
                    pivot.z = particleSystemRenderer.pivot.y * -1f;
                    pivot.y = particleSystemRenderer.pivot.z * -1f;

                    pivot *= curParticle.GetCurrentSize(particleSys);
                    break;

                default:
                    Debug.LogError("Unsupported render mode " + particleSystemRenderer.renderMode);
                    break;
                }

                // Apply rotation
                curGO.transform.Rotate(new Vector3(curParticle.rotation3D.x, curParticle.rotation3D.y, curParticle.rotation3D.z * rotationCorrection));

                // Apply scale
                curGO.transform.localScale = size;

                // Apply pivot
                pivot = Vector3.Scale(pivot, size);
                curGO.transform.position += (curGO.transform.right * pivot.x);
                curGO.transform.position += (curGO.transform.up * pivot.y);
                curGO.transform.position += (curGO.transform.forward * pivot.z * -1f);

                // Apply texture sheet animation
                ParticleSystem.TextureSheetAnimationModule texModule = particleSys.textureSheetAnimation;
                if (texModule.enabled)
                {
                    SubUVTextureInfo subUV = new SubUVTextureInfo(texModule, curParticle);

                    switch (texModule.animation)
                    {
                    case ParticleSystemAnimationType.WholeSheet:
                        curParticleCollider.gameObject.GetComponent <MeshRenderer>().material.mainTextureScale  = new Vector2(1 / subUV.columns, 1 / subUV.rows);
                        curParticleCollider.gameObject.GetComponent <MeshRenderer>().material.mainTextureOffset = new Vector2(subUV.currentColumn / subUV.columns, (subUV.rows - subUV.currentRow - 1) / subUV.rows);

                        break;

                    case ParticleSystemAnimationType.SingleRow:
                        Debug.Log("Single Row texture sheet animations currently not supported.");

                        break;

                    default:
                        Debug.Log("Unsupported texture sheet animation animation type.");

                        break;
                    }
                }

                // Apply color
                Color    particleColor = curParticle.GetCurrentColor(particleSys);
                Material mat           = curGO.GetComponent <MeshRenderer>().material;
                Color    matColor      = particleSystemRenderer.material.GetColor(TINT_COLOR);
                curGO.GetComponent <MeshRenderer>().material.SetColor(TINT_COLOR, particleColor * matColor);
            }
        }
Esempio n. 16
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                if (!Initialize())
                {
                    return;
                }
            }
#endif
            // prepare vertices
            vh.Clear();

            if (!gameObject.activeInHierarchy)
            {
                return;
            }

            Vector2 temp    = Vector2.zero;
            Vector2 corner1 = Vector2.zero;
            Vector2 corner2 = Vector2.zero;
            // iterate through current particles
            int count = pSystem.GetParticles(particles);

            for (int i = 0; i < count; ++i)
            {
                ParticleSystem.Particle particle = particles[i];

                // get particle properties
                Vector2 position   = (mainModule.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position));
                float   rotation   = -particle.rotation * Mathf.Deg2Rad;
                float   rotation90 = rotation + Mathf.PI / 2;
                Color32 color      = particle.GetCurrentColor(pSystem);
                float   size       = particle.GetCurrentSize(pSystem) * 0.5f;

                // apply scale
                if (mainModule.scalingMode == ParticleSystemScalingMode.Shape)
                {
                    position /= canvas.scaleFactor;
                }

                // apply texture sheet animation
                Vector4 particleUV = imageUV;
                if (textureSheetAnimation.enabled)
                {
                    float frameProgress = 1 - (particle.remainingLifetime / particle.startLifetime);

                    if (textureSheetAnimation.frameOverTime.curveMin != null)
                    {
                        frameProgress = textureSheetAnimation.frameOverTime.curveMin.Evaluate(1 - (particle.remainingLifetime / particle.startLifetime));
                    }
                    else if (textureSheetAnimation.frameOverTime.curve != null)
                    {
                        frameProgress = textureSheetAnimation.frameOverTime.curve.Evaluate(1 - (particle.remainingLifetime / particle.startLifetime));
                    }
                    else if (textureSheetAnimation.frameOverTime.constant > 0)
                    {
                        frameProgress = textureSheetAnimation.frameOverTime.constant - (particle.remainingLifetime / particle.startLifetime);
                    }

                    frameProgress = Mathf.Repeat(frameProgress * textureSheetAnimation.cycleCount, 1);
                    int frame = 0;

                    switch (textureSheetAnimation.animation)
                    {
                    case ParticleSystemAnimationType.WholeSheet:
                        frame = Mathf.FloorToInt(frameProgress * textureSheetAnimationFrames);
                        break;

                    case ParticleSystemAnimationType.SingleRow:
                        frame = Mathf.FloorToInt(frameProgress * textureSheetAnimation.numTilesX);

                        int row = textureSheetAnimation.rowIndex;
                        frame += row * textureSheetAnimation.numTilesX;
                        break;
                    }

                    frame %= textureSheetAnimationFrames;

                    particleUV.x = (frame % textureSheetAnimation.numTilesX) * textureSheetAnimationFrameSize.x;
                    particleUV.y = Mathf.FloorToInt(frame / textureSheetAnimation.numTilesX) * textureSheetAnimationFrameSize.y;
                    particleUV.z = particleUV.x + textureSheetAnimationFrameSize.x;
                    particleUV.w = particleUV.y + textureSheetAnimationFrameSize.y;
                }

                temp.x = particleUV.x;
                temp.y = particleUV.y;

                _quad[0]       = UIVertex.simpleVert;
                _quad[0].color = color;
                _quad[0].uv0   = temp;

                temp.x         = particleUV.x;
                temp.y         = particleUV.w;
                _quad[1]       = UIVertex.simpleVert;
                _quad[1].color = color;
                _quad[1].uv0   = temp;

                temp.x         = particleUV.z;
                temp.y         = particleUV.w;
                _quad[2]       = UIVertex.simpleVert;
                _quad[2].color = color;
                _quad[2].uv0   = temp;

                temp.x         = particleUV.z;
                temp.y         = particleUV.y;
                _quad[3]       = UIVertex.simpleVert;
                _quad[3].color = color;
                _quad[3].uv0   = temp;

                if (rotation == 0)
                {
                    // no rotation
                    corner1.x = position.x - size;
                    corner1.y = position.y - size;
                    corner2.x = position.x + size;
                    corner2.y = position.y + size;

                    temp.x            = corner1.x;
                    temp.y            = corner1.y;
                    _quad[0].position = temp;
                    temp.x            = corner1.x;
                    temp.y            = corner2.y;
                    _quad[1].position = temp;
                    temp.x            = corner2.x;
                    temp.y            = corner2.y;
                    _quad[2].position = temp;
                    temp.x            = corner2.x;
                    temp.y            = corner1.y;
                    _quad[3].position = temp;
                }
                else
                {
                    // apply rotation
                    Vector2 right = new Vector2(Mathf.Cos(rotation), Mathf.Sin(rotation)) * size;
                    Vector2 up    = new Vector2(Mathf.Cos(rotation90), Mathf.Sin(rotation90)) * size;

                    _quad[0].position = position - right - up;
                    _quad[1].position = position - right + up;
                    _quad[2].position = position + right + up;
                    _quad[3].position = position + right - up;
                }

                vh.AddUIVertexQuad(_quad);
            }
        }
Esempio n. 17
0
        private void LateUpdate()
        {
            if (m_UseMesh)
            {
                m_Verticies.Clear();
                m_Triangles.Clear();
                m_VertexColors.Clear();
            }

            CreateOrUpdateArrays();

            m_PS.GetParticles(m_Particles);
            m_ParticleCount = m_PS.particleCount;

            m_VertexIndex = 0;
            m_LineIndex   = 0;

            if (m_UseMesh)
            {
                for (int i = 0; i < m_ParticleCount; ++i)
                {
                    m_ParticleMeshData[i].ClearData();
                }
            }

            switch (m_ParticleMainModule.simulationSpace)
            {
            case ParticleSystemSimulationSpace.Local:
            {
                m_SimulationTransform = transform;
                break;
            }

            case ParticleSystemSimulationSpace.World:
            {
                m_SimulationTransform       = transform;
                m_SimulationTransformMatrix = transform.worldToLocalMatrix;
                break;
            }

            case ParticleSystemSimulationSpace.Custom:
            {
                m_SimulationTransform       = m_ParticleMainModule.customSimulationSpace;
                m_SimulationTransformMatrix = m_SimulationTransform.localToWorldMatrix * transform.worldToLocalMatrix;
                break;
            }
            }

            for (int i = 0; i < m_ParticleCount; ++i)
            {
                ParticleSystem.Particle firstParticle = m_Particles[i];
                int currentLinesCount = 0;

                if (m_LineIndex >= m_MaxLinesCount)
                {
                    break;
                }

                for (int j = i + 1; j < m_ParticleCount; ++j)
                {
                    if (currentLinesCount >= m_MaxLinesPerParticle || m_LineIndex >= m_MaxLinesCount)
                    {
                        break;
                    }

                    ParticleSystem.Particle secondParticle = m_Particles[j];

                    float particleSqrDst = (firstParticle.position - secondParticle.position).sqrMagnitude;

                    if (particleSqrDst < m_SearchDst * m_SearchDst)
                    {
                        LineRenderer line = GetNextLine();

                        line.useWorldSpace = m_ParticleMainModule.simulationSpace == ParticleSystemSimulationSpace.World;

                        line.SetPosition(0, firstParticle.position);
                        line.SetPosition(1, secondParticle.position);

                        //Set line Width
                        line.startWidth = Mathf.Lerp(m_LineWidths[0], firstParticle.GetCurrentSize(m_PS), m_LineSizeFromParticle);
                        line.endWidth   = Mathf.Lerp(m_LineWidths[1], secondParticle.GetCurrentSize(m_PS), m_LineSizeFromParticle);

                        //Set Line Color
                        line.startColor = Color.Lerp(m_LineColors[0], firstParticle.GetCurrentColor(m_PS), m_LineColorFromParticle);
                        line.endColor   = Color.Lerp(m_LineColors[1], secondParticle.GetCurrentColor(m_PS), m_LineColorFromParticle);

                        ++m_LineIndex;
                        ++currentLinesCount;

                        if (m_UseMesh)
                        {
                            m_ParticleMeshData[i].AddNeighbor(j);
                        }
                    }
                }
            }

            //Hide unused lines
            for (int i = m_LineIndex; i < m_LinePool.Count; ++i)
            {
                m_LinePool[i].gameObject.SetActive(false);
            }

            if (m_UseMesh)
            {
                SetUpMesh();
            }
            else
            {
                m_Mesh.Clear();
            }
        }
Esempio n. 18
0
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        if (ps.textureSheetAnimation.enabled)
        {
        }

        Matrix4x4 matrix = Matrix4x4.TRS(Vector3.zero, transform.rotation, Vector3.one);

        vh.Clear();

        int num = ps.GetParticles(p);

        for (int i = 0; i < num; i++)
        {
            ParticleSystem.Particle pp = p[i];

            Vector3 size = pp.GetCurrentSize3D(ps);

            if (psr.renderMode == ParticleSystemRenderMode.Billboard)
            {
                size = new Vector3(Mathf.Clamp(size.x, minSize, maxSize), Mathf.Clamp(size.y, minSize, maxSize), Mathf.Clamp(size.z, minSize, maxSize));
            }

            Color color = pp.GetCurrentColor(ps);

            Vector3 pos;

            if (ps.main.simulationSpace == ParticleSystemSimulationSpace.World)
            {
                Vector3 tp = pp.position - transform.position;

                if (ps.main.scalingMode == ParticleSystemScalingMode.Hierarchy)
                {
                    pos = new Vector3(tp.x / transform.lossyScale.x, tp.y / transform.lossyScale.y, tp.z / transform.lossyScale.z);
                }
                else
                {
                    size = size * fix;

                    size = new Vector3(size.x * canvas.rootCanvas.transform.localScale.x / transform.lossyScale.x * transform.localScale.x, size.y * canvas.rootCanvas.transform.localScale.y / transform.lossyScale.y * transform.localScale.y, size.z * canvas.transform.localScale.z / transform.lossyScale.z * transform.localScale.z);

                    pos = PublicTools.WorldPositionToCanvasPosition(m_camera, canvasRectSizeDelta, tp);

                    pos = new Vector3(pos.x * canvas.rootCanvas.transform.localScale.x / transform.lossyScale.x, pos.y * canvas.rootCanvas.transform.localScale.y / transform.lossyScale.y);
                }
            }
            else
            {
                if (ps.main.scalingMode == ParticleSystemScalingMode.Hierarchy)
                {
                    pos = pp.position;

                    pos = matrix.MultiplyPoint3x4(pos);
                }
                else
                {
                    size = size * fix;

                    size = new Vector3(size.x * canvas.rootCanvas.transform.localScale.x / transform.lossyScale.x * transform.localScale.x, size.y * canvas.rootCanvas.transform.localScale.y / transform.lossyScale.y * transform.localScale.y, size.z * canvas.transform.localScale.z / transform.lossyScale.z * transform.localScale.z);

                    pos = matrix.MultiplyPoint3x4(pp.position);

                    pos = PublicTools.WorldPositionToCanvasPosition(m_camera, canvasRectSizeDelta, pos);

                    pos = new Vector3(pos.x * canvas.rootCanvas.transform.localScale.x / transform.lossyScale.x * transform.localScale.x, pos.y * canvas.rootCanvas.transform.localScale.y / transform.lossyScale.y * transform.localScale.y);
                }
            }

            float uFix;
            float vFix;
            float uFixPlus;
            float vFixPlus;

            if (ps.textureSheetAnimation.enabled)
            {
                uFix = 1f / ps.textureSheetAnimation.numTilesX;
                vFix = 1f / ps.textureSheetAnimation.numTilesY;

                int frameNum;

                if (ps.textureSheetAnimation.animation == ParticleSystemAnimationType.WholeSheet)
                {
                    frameNum = ps.textureSheetAnimation.numTilesX * ps.textureSheetAnimation.numTilesY;
                }
                else
                {
                    frameNum = ps.textureSheetAnimation.numTilesX;
                }

                int frame;

                if (frameOverTime.mode == ParticleSystemCurveMode.Curve)
                {
                    float t = (pp.startLifetime - pp.remainingLifetime) / pp.startLifetime;

                    frame = (int)(frameOverTime.curve.Evaluate(t) * frameNum);
                }
                else if (frameOverTime.mode == ParticleSystemCurveMode.TwoConstants)
                {
                    Random.InitState((int)pp.randomSeed);

                    frame = (int)(Random.Range(frameOverTime.constantMin, frameOverTime.constantMax) * frameNum);

                    //frame = (int)(Mathf.Clamp(Random.value, frameOverTime.constantMin, frameOverTime.constantMax) * frameNum);
                }
                else if (frameOverTime.mode == ParticleSystemCurveMode.Constant)
                {
                    frame = (int)(frameOverTime.constant * frameNum);
                }
                else
                {
                    throw new System.Exception("unknown frameOverTime.mode");
                }

                if (ps.textureSheetAnimation.animation == ParticleSystemAnimationType.WholeSheet)
                {
                    uFixPlus = uFix * (frame % ps.textureSheetAnimation.numTilesX);
                    vFixPlus = vFix * (ps.textureSheetAnimation.numTilesY - 1 - frame / ps.textureSheetAnimation.numTilesX);
                }
                else
                {
                    uFixPlus = uFix * frame;
                    vFixPlus = vFix * (ps.textureSheetAnimation.numTilesY - 1 - ps.textureSheetAnimation.rowIndex);
                }
            }
            else
            {
                uFix     = 1;
                vFix     = 1;
                uFixPlus = 0;
                vFixPlus = 0;
            }

            Vector3 scale = Vector3.one;

            Quaternion qq;

            if (psr.renderMode == ParticleSystemRenderMode.Billboard)
            {
                qq = Quaternion.AngleAxis(pp.rotation, Vector3.back);
            }
            else if (psr.renderMode == ParticleSystemRenderMode.Mesh)
            {
                qq = Quaternion.AngleAxis(pp.rotation, pp.axisOfRotation);
            }
            else if (psr.renderMode == ParticleSystemRenderMode.Stretch)
            {
                Vector3 vv = matrix.inverse.MultiplyPoint3x4(pos);

                tmpTrans.localPosition = vv;

                float lengthScale = transform.lossyScale.x / transform.lossyScale.z * psr.lengthScale;

                if (ps.main.simulationSpace == ParticleSystemSimulationSpace.Local)
                {
                    tmpTrans.LookAt(transform.TransformPoint(vv + pp.velocity), Vector3.back);

                    tmpTrans.localPosition = tmpTrans.localPosition - transform.InverseTransformDirection(tmpTrans.forward) * lengthScale * 0.5f;

                    tmpTrans.Rotate(Vector3.up, 90f);

                    tmpTrans.Rotate(Vector3.left, -90f);

                    qq = tmpTrans.localRotation;
                }
                else
                {
                    tmpTrans.LookAt(transform.TransformPoint(vv) + pp.velocity, Vector3.back);

                    tmpTrans.localPosition = tmpTrans.localPosition - transform.InverseTransformDirection(tmpTrans.forward) * lengthScale * 0.5f;

                    tmpTrans.Rotate(Vector3.up, 90f);

                    tmpTrans.Rotate(Vector3.left, -90f);

                    qq = tmpTrans.rotation;
                }

                pos = matrix.MultiplyPoint3x4(tmpTrans.localPosition);

                scale.x = lengthScale;
            }
            else
            {
                throw new System.Exception("error!");
            }

            Matrix4x4 mm = Matrix4x4.TRS(Vector3.zero, qq, scale);

            if (ps.main.simulationSpace == ParticleSystemSimulationSpace.Local && psr.renderMode != ParticleSystemRenderMode.Billboard)
            {
                mm = matrix * mm;
            }

            for (int m = 0; m < vertexCount; m++)
            {
                Color nowColor = color;

                //Color nowColor = Color.clear;

                Vector3 vv = mm.MultiplyPoint3x4(vertices[m]);

                //vv = new Vector3(pos.x + vv.x * size.x, pos.y + vv.y * size.y, pos.z + vv.z * size.z);

                vv = new Vector3(pos.x + vv.x * size.x, pos.y + vv.y * size.y, 0);

                Vector3 nowPos = matrix.inverse.MultiplyPoint3x4(vv);

                Vector2 tmpUv = uv[m];

                Vector2 nowUv = new Vector2(tmpUv.x * uFix + uFixPlus, tmpUv.y * vFix + vFixPlus);

                vh.AddVert(nowPos, nowColor, nowUv);
            }

            for (int m = 0; m < triangles.Length / 3; m++)
            {
                vh.AddTriangle(i * vertexCount + triangles[m * 3], i * vertexCount + triangles[m * 3 + 1], i * vertexCount + triangles[m * 3 + 2]);
            }
        }
    }
Esempio n. 19
0
        /// <summary>
        /// Spawns prefab instances from particles that have died since the last update.
        /// </summary>
        void SpawnInstancesFromParticles()
        {
            // If there are no alive sorted particles, then skip doing anything else.
            if (sortedParticleCount <= 0)
            {
                return;
            }

            // Determine the number of newly destroyed particles.
            int particleCount  = SpriteExploder.GetParticleCount();
            int destroyedCount = sortedParticleCount - particleCount;

            // If there are newly destroyed particles, then we'll potentially spawn
            // instances of the prefab in their place.
            if (destroyedCount > 0)
            {
                Texture2D texture    = SpriteExploder.GetTexture();
                Vector2   flipVector = SpriteExploder.GetFlipVector2();

                // Enumerate through the destroyed count and spawn instances where
                // the particle tile's texture color isn't clear in the center.
                for (int i = 0; i < destroyedCount; i++)
                {
                    // The Sprite Exploder works by sending index values in the custom
                    // data stream to the shader. The index value is stored in the x property.
                    int tileIndex = (int)customDatas[i].x;

                    // With the particle tile index, we can get the tile X and y values
                    // from the Sprite Exploder.
                    int tileX = SpriteExploder.GetTileX(tileIndex, tileCountX);
                    if (flipVector.x < 0)
                    {
                        tileX = tileCountX - tileX;
                    }

                    int tileY = SpriteExploder.GetTileY(tileIndex, tileCountY);
                    if (flipVector.y < 0)
                    {
                        tileY = tileCountY - tileY;
                    }

                    // With tile x and y values, we can determing the texture x and y
                    // values of particle tile.
                    int tileCenterPixelX = tileX * pixelSize + centerOffset;
                    int tileCenterPixelY = tileY * pixelSize + centerOffset;

                    Color color = texture.GetPixel(tileCenterPixelX, tileCenterPixelY);

                    // If the center particle is totally clear then skip making an
                    // instance since the tile will likely look empty or too small.
                    if (color.a <= 0.0f)
                    {
                        continue;
                    }

                    // Get a reference to the particle and its current color.
                    ParticleSystem.Particle particle = particles[i];
                    Color32 spawnColor = particle.GetCurrentColor(spriteExploderParticleSystem);

                    // Spawn an instance of the prefab with the particle's transform data and color
                    GameObject instance = Spawn(particle.position, particleScale, particle.rotation, particle.velocity, particle.angularVelocity, spawnColor);
                    // Invoke the OnInstanceCreated event for any outside class that are handling that.
                    OnInstanceCreated?.Invoke(instance);
                }
            }

            // Update the custom particle data
            UpdateCustomParticleData();

            // If there are no more particles, then invoke the completed event.
            if (sortedParticleCount <= 0)
            {
                OnCompleted?.Invoke();
            }
        }
Esempio n. 20
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                if (!Initialize())
                {
                    return;
                }
            }
#endif
            // prepare vertices
            vh.Clear();

            if (!gameObject.activeInHierarchy)
            {
                return;
            }

            if (!isInitialised && !pSystem.main.playOnAwake)
            {
                pSystem.Stop(false, ParticleSystemStopBehavior.StopEmittingAndClear);
                isInitialised = true;
            }

            Vector2 temp    = Vector2.zero;
            Vector2 corner1 = Vector2.zero;
            Vector2 corner2 = Vector2.zero;
            // iterate through current particles
            int count = pSystem.GetParticles(particles);

            for (int i = 0; i < count; ++i)
            {
                ParticleSystem.Particle particle = particles[i];

                // get particle properties
#if UNITY_5_5_OR_NEWER
                Vector2 position = (mainModule.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position));
#else
                Vector2 position = (pSystem.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position));
#endif
                float   rotation   = -particle.rotation * Mathf.Deg2Rad;
                float   rotation90 = rotation + Mathf.PI / 2;
                Color32 color      = particle.GetCurrentColor(pSystem);
                float   size       = particle.GetCurrentSize(pSystem) * 0.5f;

                // apply scale
#if UNITY_5_5_OR_NEWER
                if (mainModule.scalingMode == ParticleSystemScalingMode.Shape)
                {
                    position /= canvas.scaleFactor;
                }
#else
                if (pSystem.scalingMode == ParticleSystemScalingMode.Shape)
                {
                    position /= canvas.scaleFactor;
                }
#endif

                // apply texture sheet animation
                Vector4 particleUV = imageUV;
                if (textureSheetAnimation.enabled)
                {
#if UNITY_5_5_OR_NEWER
                    float frameProgress = 1 - (particle.remainingLifetime / particle.startLifetime);

                    if (textureSheetAnimation.frameOverTime.curveMin != null)
                    {
                        frameProgress = textureSheetAnimation.frameOverTime.curveMin.Evaluate(1 - (particle.remainingLifetime / particle.startLifetime));
                    }
                    else if (textureSheetAnimation.frameOverTime.curve != null)
                    {
                        frameProgress = textureSheetAnimation.frameOverTime.curve.Evaluate(1 - (particle.remainingLifetime / particle.startLifetime));
                    }
                    else if (textureSheetAnimation.frameOverTime.constant > 0)
                    {
                        frameProgress = textureSheetAnimation.frameOverTime.constant - (particle.remainingLifetime / particle.startLifetime);
                    }
#else
                    float frameProgress = 1 - (particle.lifetime / particle.startLifetime);
#endif

                    frameProgress = Mathf.Repeat(frameProgress * textureSheetAnimation.cycleCount, 1);
                    int frame = 0;

                    switch (textureSheetAnimation.animation)
                    {
                    case ParticleSystemAnimationType.WholeSheet:
                        frame = Mathf.FloorToInt(frameProgress * textureSheetAnimationFrames);
                        break;

                    case ParticleSystemAnimationType.SingleRow:
                        frame = Mathf.FloorToInt(frameProgress * textureSheetAnimation.numTilesX);

                        int row = textureSheetAnimation.rowIndex;
                        //                    if (textureSheetAnimation.useRandomRow) { // FIXME - is this handled internally by rowIndex?
                        //                        row = Random.Range(0, textureSheetAnimation.numTilesY, using: particle.randomSeed);
                        //                    }
                        frame += row * textureSheetAnimation.numTilesX;
                        break;
                    }

                    frame %= textureSheetAnimationFrames;

                    particleUV.x = (frame % textureSheetAnimation.numTilesX) * textureSheetAnimationFrameSize.x;
                    particleUV.y = 1.0f - Mathf.FloorToInt(frame / textureSheetAnimation.numTilesX) * textureSheetAnimationFrameSize.y;
                    particleUV.z = particleUV.x + textureSheetAnimationFrameSize.x;
                    particleUV.w = particleUV.y + textureSheetAnimationFrameSize.y;
                }

                temp.x = particleUV.x;
                temp.y = particleUV.y;

                _quad[0]       = UIVertex.simpleVert;
                _quad[0].color = color;
                _quad[0].uv0   = temp;

                temp.x         = particleUV.x;
                temp.y         = particleUV.w;
                _quad[1]       = UIVertex.simpleVert;
                _quad[1].color = color;
                _quad[1].uv0   = temp;

                temp.x         = particleUV.z;
                temp.y         = particleUV.w;
                _quad[2]       = UIVertex.simpleVert;
                _quad[2].color = color;
                _quad[2].uv0   = temp;

                temp.x         = particleUV.z;
                temp.y         = particleUV.y;
                _quad[3]       = UIVertex.simpleVert;
                _quad[3].color = color;
                _quad[3].uv0   = temp;

                if (rotation == 0)
                {
                    // no rotation
                    corner1.x = position.x - size;
                    corner1.y = position.y - size;
                    corner2.x = position.x + size;
                    corner2.y = position.y + size;

                    temp.x            = corner1.x;
                    temp.y            = corner1.y;
                    _quad[0].position = temp;
                    temp.x            = corner1.x;
                    temp.y            = corner2.y;
                    _quad[1].position = temp;
                    temp.x            = corner2.x;
                    temp.y            = corner2.y;
                    _quad[2].position = temp;
                    temp.x            = corner2.x;
                    temp.y            = corner1.y;
                    _quad[3].position = temp;
                }
                else
                {
                    if (use3dRotation)
                    {
                        // get particle properties
#if UNITY_5_5_OR_NEWER
                        Vector3 pos3d = (mainModule.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position));
#else
                        Vector3 pos3d = (pSystem.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position));
#endif

                        // apply scale
#if UNITY_5_5_OR_NEWER
                        if (mainModule.scalingMode == ParticleSystemScalingMode.Shape)
                        {
                            position /= canvas.scaleFactor;
                        }
#else
                        if (pSystem.scalingMode == ParticleSystemScalingMode.Shape)
                        {
                            position /= canvas.scaleFactor;
                        }
#endif

                        Vector3[] verts = new Vector3[4]
                        {
                            new Vector3(-size, -size, 0),
                            new Vector3(-size, size, 0),
                            new Vector3(size, size, 0),
                            new Vector3(size, -size, 0)
                        };

                        Quaternion particleRotation = Quaternion.Euler(particle.rotation3D);

                        _quad[0].position = pos3d + particleRotation * verts[0];
                        _quad[1].position = pos3d + particleRotation * verts[1];
                        _quad[2].position = pos3d + particleRotation * verts[2];
                        _quad[3].position = pos3d + particleRotation * verts[3];
                    }
                    else
                    {
                        // apply rotation
                        Vector2 right = new Vector2(Mathf.Cos(rotation), Mathf.Sin(rotation)) * size;
                        Vector2 up    = new Vector2(Mathf.Cos(rotation90), Mathf.Sin(rotation90)) * size;

                        _quad[0].position = position - right - up;
                        _quad[1].position = position - right + up;
                        _quad[2].position = position + right + up;
                        _quad[3].position = position + right - up;
                    }
                }

                vh.AddUIVertexQuad(_quad);
            }
        }
Esempio n. 21
0
 /// <summary>
 ///  Handles the particle update
 /// </summary>
 /// <param name="particle">Current assigned particle</param>
 protected override void HandleParticleUpdate(ParticleSystem.Particle particle, ParticleSystem particleSystem)
 {
     this.lightSource.intensity = this.intensitySizeRelation * particle.GetCurrentSize(particleSystem);
     this.lightSource.color     = particle.GetCurrentColor(particleSystem);
 }
Esempio n. 22
0
    void UpdateGeometry()
    {
#if UNITY_EDITOR
        if (mUpdateFrame != Time.frameCount || !Application.isPlaying)
#else
        if (mUpdateFrame != Time.frameCount)
#endif
        {
            mUpdateFrame = Time.frameCount;

            if (GetComponent <ParticleSystem>() != null)
            {
                //
                int max_particles = GetComponent <ParticleSystem>().maxParticles;
                m_Particles.Adjust(max_particles);
                bool isBufferChanged = m_Meshes.Adjust(max_particles, true);

                ParticleSystem.Particle[] particles = m_Particles.GetBuffer();
                GetComponent <ParticleSystem>().GetParticles(particles);

                //
                ParticleMesh[] meshes         = m_Meshes.GetBuffer();
                int            mesh_count     = meshes.Length;
                int            particle_count = GetComponent <ParticleSystem>().particleCount;

                if (isBufferChanged)
                {
                    UnityEngine.Profiling.Profiler.BeginSample("FXBillboardParticle 001");
                    for (int i = particle_count; i < mesh_count; i++)
                    {
                        if (meshes[i].m_Renderer != null)
                        {
                            meshes[i].m_Renderer.enabled = false;
                        }
                    }
                    UnityEngine.Profiling.Profiler.EndSample();
                }

                UnityEngine.Profiling.Profiler.BeginSample("FXBillboardParticle 002");
                for (int i = 0; i < particle_count; i++)
                {
                    ParticleSystem.Particle particle = particles[i];

                    float     factor           = (particle.startLifetime - particle.remainingLifetime) / particle.startLifetime;
                    float     size             = particle.GetCurrentSize(GetComponent <ParticleSystem>()) * Mathf.Lerp(FromSize, ToSize, factor);
                    Matrix4x4 transform_matrix = Matrix4x4.TRS(particle.position,
                                                               Quaternion.AngleAxis(particle.rotation, -Camera.main.transform.forward),
                                                               new Vector3(size, size, size));

                    meshes[i].PreUpdate(transform);

                    if (AtlasType == FXAtlasType.Static)
                    {
                        if (meshes[i].m_Renderer != null && m_Atlas != null)
                        {
                            meshes[i].m_Renderer.sharedMaterial = m_Atlas.spriteMaterial;
                            meshes[i].m_Renderer.enabled        = true;
                        }
                    }
                    else if (AtlasType == FXAtlasType.Dynamic)
                    {
                        DynamicAtlasManager dynamic_atlas_manager = DynamicAtlasManager.GetInstance();
                        if (meshes[i].m_Renderer != null && dynamic_atlas_manager != null)
                        {
                            DynamicAtlas dynamic_atlas = dynamic_atlas_manager.GetDynamicAtlas(m_DynamicAtlasType);
                            if (dynamic_atlas != null)
                            {
                                meshes[i].m_Renderer.sharedMaterial = dynamic_atlas.m_Material;
                                meshes[i].m_Renderer.enabled        = true;
                            }
                        }
                    }

                    if (GetComponent <ParticleSystem>().simulationSpace == ParticleSystemSimulationSpace.Local)
                    {
                        meshes[i].m_Vertices[0].Set(-0.5f, -0.5f, 0);
                        meshes[i].m_Vertices[0] = transform_matrix.MultiplyPoint(meshes[i].m_Vertices[0]);

                        meshes[i].m_Vertices[1].Set(-0.5f, 0.5f, 0);
                        meshes[i].m_Vertices[1] = transform_matrix.MultiplyPoint(meshes[i].m_Vertices[1]);

                        meshes[i].m_Vertices[2].Set(0.5f, 0.5f, 0);
                        meshes[i].m_Vertices[2] = transform_matrix.MultiplyPoint(meshes[i].m_Vertices[2]);

                        meshes[i].m_Vertices[3].Set(0.5f, -0.5f, 0);
                        meshes[i].m_Vertices[3] = transform_matrix.MultiplyPoint(meshes[i].m_Vertices[3]);
                    }
                    else
                    {
                        Matrix4x4 world2local_matrix = transform.worldToLocalMatrix;

                        meshes[i].m_Vertices[0].Set(-0.5f, -0.5f, 0);
                        meshes[i].m_Vertices[0] = transform_matrix.MultiplyPoint(meshes[i].m_Vertices[0]);
                        meshes[i].m_Vertices[0] = world2local_matrix.MultiplyPoint(meshes[i].m_Vertices[0]);

                        meshes[i].m_Vertices[1].Set(-0.5f, 0.5f, 0);
                        meshes[i].m_Vertices[1] = transform_matrix.MultiplyPoint(meshes[i].m_Vertices[1]);
                        meshes[i].m_Vertices[1] = world2local_matrix.MultiplyPoint(meshes[i].m_Vertices[1]);

                        meshes[i].m_Vertices[2].Set(0.5f, 0.5f, 0);
                        meshes[i].m_Vertices[2] = transform_matrix.MultiplyPoint(meshes[i].m_Vertices[2]);
                        meshes[i].m_Vertices[2] = world2local_matrix.MultiplyPoint(meshes[i].m_Vertices[2]);

                        meshes[i].m_Vertices[3].Set(0.5f, -0.5f, 0);
                        meshes[i].m_Vertices[3] = transform_matrix.MultiplyPoint(meshes[i].m_Vertices[3]);
                        meshes[i].m_Vertices[3] = world2local_matrix.MultiplyPoint(meshes[i].m_Vertices[3]);
                    }

                    //
                    Rect  uv          = m_SpriteUV;
                    float frame       = TileX * TileY * factor;
                    int   frame_index = (int)frame;
                    int   frameX      = frame_index % TileX;
                    int   frameY      = TileY - frame_index / TileY - 1;
                    float stepX       = m_SpriteUV.width / (float)TileX;
                    float stepY       = m_SpriteUV.height / (float)TileY;
                    uv.Set(stepX * frameX + m_SpriteUV.x, stepY * frameY + m_SpriteUV.y, stepX, stepY);

                    meshes[i].m_UVs[0].Set(uv.xMin, uv.yMin);
                    meshes[i].m_UVs[1].Set(uv.xMin, uv.yMax);
                    meshes[i].m_UVs[2].Set(uv.xMax, uv.yMax);
                    meshes[i].m_UVs[3].Set(uv.xMax, uv.yMin);

                    //
                    Color color = particle.GetCurrentColor(GetComponent <ParticleSystem>()) * Color.Lerp(FromColor, ToColor, factor);
                    meshes[i].m_Colors[0] = color;
                    meshes[i].m_Colors[1] = color;
                    meshes[i].m_Colors[2] = color;
                    meshes[i].m_Colors[3] = color;

                    meshes[i].m_Indices[0] = 0;
                    meshes[i].m_Indices[1] = 1;
                    meshes[i].m_Indices[2] = 2;
                    meshes[i].m_Indices[3] = 0;
                    meshes[i].m_Indices[4] = 2;
                    meshes[i].m_Indices[5] = 3;

                    meshes[i].Update();
                }
                UnityEngine.Profiling.Profiler.EndSample();
            }
        }
    }
Esempio n. 23
0
        private void DrawParticleBillboard(ParticleSystem.Particle particle, VertexHelper vh)
        {
            /*Vector3 vector = particle.get_position();
             *          Quaternion quaternion = Quaternion.Euler(particle.get_rotation3D());
             *          if (this.ParticleSystem.get_main().get_simulationSpace() == 1)
             *          {
             *                  vector = base.get_rectTransform().InverseTransformPoint(vector);
             *          }
             *          float num = particle.get_startLifetime() - particle.get_remainingLifetime();
             *          float timeAlive = num / particle.get_startLifetime();
             *          Vector3 currentSize3D = particle.GetCurrentSize3D(this.ParticleSystem);
             *          if (this.m_RenderMode == UiParticleRenderMode.StreachedBillboard)
             *          {
             *                  this.GetStrechedBillboardsSizeAndRotation(particle, timeAlive, ref currentSize3D, out quaternion);
             *          }
             *          Vector3 vector2 = new Vector3(-currentSize3D.x * 0.5f, currentSize3D.y * 0.5f);
             *          Vector3 vector3 = new Vector3(currentSize3D.x * 0.5f, currentSize3D.y * 0.5f);
             *          Vector3 vector4 = new Vector3(currentSize3D.x * 0.5f, -currentSize3D.y * 0.5f);
             *          Vector3 vector5 = new Vector3(-currentSize3D.x * 0.5f, -currentSize3D.y * 0.5f);
             *          vector2 = quaternion * vector2 + vector;
             *          vector3 = quaternion * vector3 + vector;
             *          vector4 = quaternion * vector4 + vector;
             *          vector5 = quaternion * vector5 + vector;
             *          Color32 currentColor = particle.GetCurrentColor(this.ParticleSystem);
             *          int currentVertCount = vh.get_currentVertCount();
             *          Vector2[] array = new Vector2[4];
             *          if (!this.ParticleSystem.get_textureSheetAnimation().get_enabled())
             *          {
             *                  this.EvaluateQuadUVs(array);
             *          }
             *          else
             *          {
             *                  this.EvaluateTexturesheetUVs(particle, num, array);
             *          }
             *          vh.AddVert(vector5, currentColor, array[0]);
             *          vh.AddVert(vector2, currentColor, array[1]);
             *          vh.AddVert(vector3, currentColor, array[2]);
             *          vh.AddVert(vector4, currentColor, array[3]);
             *          vh.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2);
             *          vh.AddTriangle(currentVertCount + 2, currentVertCount + 3, currentVertCount);*/

            Vector3    vector     = particle.position;
            Quaternion quaternion = Quaternion.Euler(particle.rotation3D);

            if (this.ParticleSystem.main.simulationSpace == ParticleSystemSimulationSpace.World)
            {
                vector = base.rectTransform.InverseTransformPoint(vector);
            }
            float   num           = particle.startLifetime - particle.remainingLifetime;
            float   timeAlive     = num / particle.startLifetime;
            Vector3 currentSize3D = particle.GetCurrentSize3D(this.ParticleSystem);

            if (this.m_RenderMode == UiParticleRenderMode.StreachedBillboard)
            {
                this.GetStrechedBillboardsSizeAndRotation(particle, timeAlive, ref currentSize3D, out quaternion);
            }
            Vector3 vector2 = new Vector3(-currentSize3D.x * 0.5f, currentSize3D.y * 0.5f);
            Vector3 vector3 = new Vector3(currentSize3D.x * 0.5f, currentSize3D.y * 0.5f);
            Vector3 vector4 = new Vector3(currentSize3D.x * 0.5f, -currentSize3D.y * 0.5f);
            Vector3 vector5 = new Vector3(-currentSize3D.x * 0.5f, -currentSize3D.y * 0.5f);

            vector2 = quaternion * vector2 + vector;
            vector3 = quaternion * vector3 + vector;
            vector4 = quaternion * vector4 + vector;
            vector5 = quaternion * vector5 + vector;
            Color32 currentColor     = particle.GetCurrentColor(this.ParticleSystem);
            int     currentVertCount = vh.currentVertCount;

            Vector2[] array = new Vector2[4];
            if (!this.ParticleSystem.textureSheetAnimation.enabled)
            {
                this.EvaluateQuadUVs(array);
            }
            else
            {
                this.EvaluateTexturesheetUVs(particle, num, array);
            }
            vh.AddVert(vector5, currentColor, array[0]);
            vh.AddVert(vector2, currentColor, array[1]);
            vh.AddVert(vector3, currentColor, array[2]);
            vh.AddVert(vector4, currentColor, array[3]);
            vh.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2);
            vh.AddTriangle(currentVertCount + 2, currentVertCount + 3, currentVertCount);
        }