Пример #1
0
    private void IntitBackSea()
    {
        List <Vector3> verts = new List <Vector3>();
        List <int>     tris  = new List <int>();

        seaRendererHeight = backSeaMeshFilter.transform.position.y;

        float heightOffset = Mathf.Sqrt(seaEdgeSize * seaEdgeSize - seaEdgeSize * seaEdgeSize * 0.5f * 0.5f);

        int     sign = 1;
        Vector3 currentStartPoint = new Vector3(0f, 0f, 0f);

        for (int i = 0; i < backSeaSize.y; i++)
        {
            for (int j = 0; j < backSeaSize.x; j++)
            {
                if (i < backSeaSize.y - 1 && j < backSeaSize.x - 1)
                {
                    if (sign > 0)
                    {
                        verts.Add(currentStartPoint.AddToX(j * seaEdgeSize));
                        verts.Add(currentStartPoint.AddToX(j * seaEdgeSize + seaEdgeSize * 0.5f).AddToZ(heightOffset));
                        verts.Add(currentStartPoint.AddToX(j * seaEdgeSize + seaEdgeSize));

                        tris.AddRange(new int[] { verts.Count - 3, verts.Count - 2, verts.Count - 1 });

                        verts.Add(currentStartPoint.AddToX(j * seaEdgeSize + seaEdgeSize));
                        verts.Add(currentStartPoint.AddToX(j * seaEdgeSize + seaEdgeSize * 0.5f).AddToZ(heightOffset));
                        verts.Add(currentStartPoint.AddToX(j * seaEdgeSize + seaEdgeSize * 0.5f + seaEdgeSize).AddToZ(heightOffset));

                        tris.AddRange(new int[] { verts.Count - 3, verts.Count - 2, verts.Count - 1 });
                    }
                    else
                    {
                        verts.Add(currentStartPoint.AddToX(j * seaEdgeSize));
                        verts.Add(currentStartPoint.AddToX(j * seaEdgeSize - seaEdgeSize * 0.5f).AddToZ(heightOffset));
                        verts.Add(currentStartPoint.AddToX(j * seaEdgeSize + seaEdgeSize * 0.5f).AddToZ(heightOffset));

                        tris.AddRange(new int[] { verts.Count - 3, verts.Count - 2, verts.Count - 1 });

                        verts.Add(currentStartPoint.AddToX(j * seaEdgeSize));
                        verts.Add(currentStartPoint.AddToX(j * seaEdgeSize + seaEdgeSize * 0.5f).AddToZ(heightOffset));
                        verts.Add(currentStartPoint.AddToX(j * seaEdgeSize + seaEdgeSize));

                        tris.AddRange(new int[] { verts.Count - 3, verts.Count - 2, verts.Count - 1 });
                    }
                }
            }

            currentStartPoint = currentStartPoint.AddToZ(heightOffset).AddToX(seaEdgeSize * 0.5f * sign);
            sign *= -1;
        }

        Mesh mesh = new Mesh();

        initialVertsPos = verts.ToArray();
        mesh.vertices   = initialVertsPos;
        mesh.triangles  = tris.ToArray();

        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
        backSeaMeshFilter.mesh = mesh;

        StartCoroutine(BackSeaAnimation());
    }