Пример #1
0
    // Update is called once per frame
    void Update()
    {
        tick += Time.deltaTime;
        if (tick < 0.05f)
        {
            return;
        }
        tick = 0f;
        int  c     = list.Count;
        bool dirty = false;

        for (int i = c - 1; i >= 0; i--)
        {
            GhostShadowObject o = list[i];
            if (Time.realtimeSinceStartup - o.time > fadeTime)
            {
                list.RemoveAt(i);
                dirty = true;
            }
        }
        if (dirty)
        {
            RenderMesh(list);
        }
    }
Пример #2
0
    public void RenderMesh(System.Collections.Generic.List <GhostShadowObject> list)
    {
        mesh.Clear();
        meshRenderer.material.mainTexture = renderTarget;
        int   len       = list.Count;
        float uvdelta   = ((float)delta) / size;
        int   row_count = size / delta;

        Vector3[]  vertices = new Vector3[4 * len];
        Color []   colors   = new Color[4 * len];
        Vector2 [] uvs      = new Vector2[4 * len];
        Vector3 [] normals  = new Vector3[4 * len];
        for (int i = 0; i < len; i++)
        {
            GhostShadowObject o = list[i];

            float f = (Time.realtimeSinceStartup - o.time) / fadeTime;

            int _x = o.index / row_count;
            int _y = o.index % row_count;
            uvs[i * 4 + 0] = new Vector3(_x * uvdelta, _y * uvdelta, 0f);
            uvs[i * 4 + 1] = new Vector3(_x * uvdelta, (_y + 1) * uvdelta, 0f);
            uvs[i * 4 + 2] = new Vector3((_x + 1) * uvdelta, _y * uvdelta, 0f);
            uvs[i * 4 + 3] = new Vector3((_x + 1) * uvdelta, (_y + 1) * uvdelta, 0f);



            vertices[i * 4 + 0] = new Vector3(-0.5f * o.height * _scale, 0 * o.height * _scale, 0f) + o.position;
            vertices[i * 4 + 1] = new Vector3(-0.5f * o.height * _scale, 1f * o.height * _scale, 0f) + o.position;
            vertices[i * 4 + 2] = new Vector3(0.5f * o.height * _scale, 0 * o.height * _scale, 0f) + o.position;
            vertices[i * 4 + 3] = new Vector3(0.5f * o.height * _scale, 1f * o.height * _scale, 0f) + o.position;

            colors[i * 4 + 0]  = colors[i * 4 + 1] = colors[i * 4 + 2] = colors[i * 4 + 3] = new Color(o.color.r, o.color.g, o.color.b, 1f);//Mathf.Lerp(0.9f,0.3f,f));
            normals[i * 4 + 0] = normals[i * 4 + 1] = normals[i * 4 + 2] = normals[i * 4 + 3] = new Vector3(0f, 0f, -1f);
        }

        int [] triangles = new int [6 * len];
        int    _len      = triangles.Length;

        for (int i = 0; i < _len / 6; i++)
        {
            triangles[i * 6 + 0] = i * 4 + 0;
            triangles[i * 6 + 1] = i * 4 + 1;
            triangles[i * 6 + 2] = i * 4 + 2;
            triangles[i * 6 + 3] = i * 4 + 2;
            triangles[i * 6 + 4] = i * 4 + 1;
            triangles[i * 6 + 5] = i * 4 + 3;
        }
        globalMeshRender.transform.position = Vector3.zero;
        mesh.vertices  = vertices;
        mesh.colors    = colors;
        mesh.normals   = normals;
        mesh.uv        = uvs;
        mesh.triangles = triangles;
    }