Ejemplo n.º 1
0
        public Unity_MapTileMap LoadTileSet(PCX pcx)
        {
            // Get the tilemap texture
            var tileMap = pcx.ToTexture();

            var tileSetWidth  = tileMap.width / Settings.CellSize;
            var tileSetHeight = tileMap.height / Settings.CellSize;

            // Create the tile array
            var tiles = new Unity_TileTexture[tileSetWidth * tileSetHeight];

            // Get the transparency color
            var transparencyColor = tileMap.GetPixel(0, 0);

            // Replace the transparency color with true transparency
            for (int y = 0; y < tileMap.height; y++)
            {
                for (int x = 0; x < tileMap.width; x++)
                {
                    if (tileMap.GetPixel(x, y) == transparencyColor)
                    {
                        tileMap.SetPixel(x, y, new Color(0, 0, 0, 0));
                    }
                }
            }

            tileMap.Apply();

            // Split the .pcx into a tile-set
            for (int ty = 0; ty < tileSetHeight; ty++)
            {
                for (int tx = 0; tx < tileSetWidth; tx++)
                {
                    // Create a tile
                    tiles[ty * tileSetWidth + tx] = tileMap.CreateTile(new Rect(tx * Settings.CellSize, ty * Settings.CellSize, Settings.CellSize, Settings.CellSize));
                }
            }

            return(new Unity_MapTileMap(tiles));
        }