protected async UniTask <PCX> LoadPCXAsync(Context context, int index) { var xor = LoadVignetteHeader(context)[index].XORKey; var path = GetVignetteFilePath(index); await AddFile(context, path); var s = context.Deserializer; PCX pcx = null; s.DoAt(context.GetFile(path).StartPointer, () => { s.DoXOR(xor, () => { // Read the data pcx = s.SerializeObject <PCX>(default, name: $"VIGNET");
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)); }