Пример #1
0
 private Vector2[] GetNewUVs(BoardCellType newCellType, BoardCellIndex cellIndex)
 {
     if (IsBorder(cellIndex))
     {
         return(BoardCellUVsFactory.GetTransparentUVs());
     }
     else
     {
         return(BoardCellUVsFactory.GetUVsFor(newCellType));
     }
 }
Пример #2
0
    private Mesh CreateMesh()
    {
        var totalNumberOfCells = numberOfCells.x * numberOfCells.y;

        var vertices  = new List <Vector3>(totalNumberOfCells * 4);
        var triangles = new List <int>(totalNumberOfCells * 6);
        var uvs       = new List <Vector2>(totalNumberOfCells * 4);

        ForEachCell(cell =>
        {
            var cellCenter = CalculateLocalCellCenter(cell.Index);

            var firstVertex = vertices.Count;

            vertices.Add(cellCenter + new Vector3(-cellSize.x / 2.0f, -cellSize.y / 2.0f, 0.0f));
            vertices.Add(cellCenter + new Vector3(cellSize.x / 2.0f, -cellSize.y / 2.0f, 0.0f));
            vertices.Add(cellCenter + new Vector3(cellSize.x / 2.0f, cellSize.y / 2.0f, 0.0f));
            vertices.Add(cellCenter + new Vector3(-cellSize.x / 2.0f, cellSize.y / 2.0f, 0.0f));

            triangles.Add(firstVertex);
            triangles.Add(firstVertex + 2);
            triangles.Add(firstVertex + 1);

            triangles.Add(firstVertex + 2);
            triangles.Add(firstVertex);
            triangles.Add(firstVertex + 3);

            if (IsBorder(cell.Index))
            {
                uvs.AddRange(BoardCellUVsFactory.GetTransparentUVs());
            }
            else
            {
                uvs.AddRange(BoardCellUVsFactory.GetUVsFor(cell.Type));
            }
        });

        var mesh = new Mesh();

        mesh.indexFormat = IndexFormat.UInt32; // needed?
        mesh.vertices    = vertices.ToArray();
        mesh.triangles   = triangles.ToArray();
        mesh.uv          = uvs.ToArray();

        mesh.RecalculateNormals();

        return(mesh);
    }