Exemple #1
0
    public static void Build(LevelEnvironmentData data, TileData tile, Vector3 worldPosition, byte bitmask)
    {
        foreach (Line edge in tile.Brush.GetEdgeCoordinates(bitmask))
        {
            int vertexCount = data.Vertices.Count;

            // Vertices.
            Vector3 scaledA = Utility.ScaleToHexagonalSize(edge.A) + worldPosition;
            Vector3 scaledB = Utility.ScaleToHexagonalSize(edge.B) + worldPosition;

            data.Vertices.AddRange(new Vector3[4]
            {
                scaledA,
                scaledB,
                scaledB + new Vector3(0, 0, EdgeDepth),
                scaledA + new Vector3(0, 0, EdgeDepth),
            });

            // Triangles.
            data.SetTriangles(tile.EdgeMaterial, new int[6]
            {
                vertexCount + 0, vertexCount + 1, vertexCount + 2,
                vertexCount + 2, vertexCount + 3, vertexCount + 0,
            });

            // UVs.
            data.UVs.AddRange(new List <Vector2>()
            {
                new Vector2(0, 1),
                new Vector2(1, 1),
                new Vector2(1, 0),
                new Vector2(0, 0),
            });
        }
    }
Exemple #2
0
    private static void AddTileToLevel(LevelEnvironmentData data, TileData tile, Vector3 worldPosition, byte bitmask)
    {
        int verticeCount = data.Vertices.Count;

        TileMeshData meshData = tile.Brush.GetMeshData(bitmask);

        // Vertices.
        foreach (Vector3 vertex in meshData.Vertices)
        {
            data.Vertices.Add(Utility.ScaleToHexagonalSize(vertex) + worldPosition);
        }

        // Triangles.
        int[][] rawTriangles = meshData.Triangles;
        for (int i = 0; i < rawTriangles.Length; i++)
        {
            int[] trianglesToSet = new int[rawTriangles[i].Length];

            // Offset the triangles
            for (int w = 0; w < rawTriangles[i].Length; w++)
            {
                trianglesToSet[w] = rawTriangles[i][w] + verticeCount;
            }

            data.SetTriangles(tile.BrushMaterials[i], trianglesToSet);
        }

        // UVs.
        foreach (Vector2 uv in meshData.UVs)
        {
            data.UVs.Add(uv);
        }

        // Edges.
        if (!AxialDirection.ContainsDirection(bitmask, AxialDirection.DownLeft) || !AxialDirection.ContainsDirection(bitmask, AxialDirection.DownRight))
        {
            EdgeBuilder.Build(data, tile, worldPosition, bitmask);
        }
    }