private void BuildTexture(TileSetLayer tileSetLayer) {

        int textureWidth = numberTilesX * tileResolution;
        int textureHeight = numberTilesY * tileResolution;

        Texture2D texture = new Texture2D(textureWidth, textureHeight);
        texture.alphaIsTransparency = true;

        Color[][] tiles = SplitTileset();

        Debug.Log(">> Build Texture");
        Debug.Log("   # Texture Resolution: " + texture.width + " x " + texture.width);

        int tileRowIndex = 0;
        for (int y = numberTilesY - 1; y > -1; y--) {
            int lineInPixels = y * tileResolution;
            for (int x = 0; x < numberTilesX; x++) {
                Color[] tile = transparentColor;

                int tileID = tileSetLayer.Tiles[x, tileRowIndex];
                if (tileID != TileSetLayer.EMPTY_TILE) {
                    tile = tiles[tileID - 1];
                    if (tileSetLayer.Opacity < ALPHA_OPAQUE) {
                        SetOpacity(tile, tileSetLayer.Opacity);
                    }
                }

                texture.SetPixels(x * tileResolution, lineInPixels, tileResolution, tileResolution, tile);
            }
            tileRowIndex++;
        }

        texture.filterMode = FilterMode;
        texture.wrapMode = WrapMode;
        texture.Apply();

        MeshRenderer meshRenderer = GetComponent<MeshRenderer>();
        meshRenderer.material.mainTexture = texture;
    }
        private static TileSetLayer ParserTileSetLayer(XmlNode tilesetLayerNode) {

            int width = -1;
            int height = -1;

            for (int i = 0; i < tilesetLayerNode.Attributes.Count; i++) {
                XmlNode attribute = tilesetLayerNode.Attributes.Item(i);
                string attributeName = tilesetLayerNode.Attributes.Item(i).Name;

                switch (attributeName) {
                     case "width":
                        width = int.Parse(attribute.Value);
                        break;
                    case "height":
                        height = int.Parse(attribute.Value);
                        break;
                    default:
                        break;
                }
            }

            string name;
            float offsetX;
            float offsetY;
            bool visible;
            float opacity;

            ParserLayerBaseAttributes(tilesetLayerNode, out name, out offsetX, out offsetY, out visible, out opacity);
            TileSetLayer tileSetLayer = new TileSetLayer(width, height, name, offsetX, offsetY, opacity, visible);

            XmlNode dataNode = tilesetLayerNode.ChildNodes.Item(0);
            string[] data = dataNode.InnerText.Split(',');
            int y = 0;
            int x = 0;
            for (int i = 0; i < data.Length; i++) {
                tileSetLayer.Tiles[x, y] = int.Parse(data[i]);
                if ((i + 1) % width == 0) {
                    x = 0;
                    y++;
                } else {
                    x++;
                }
            }

            return tileSetLayer;
        }