public static new void Generate_Tiles(string path, List <Texture2D> sub_blocks, List <bool> sub_blocks_to_import, int mini_tile_w, int mini_tile_h, int wBlock, int hBlock, bool generate_sprite_sheet_image) { //create the final directory for the auto tile if (!Directory.Exists(Tiles_Utility.Auto_Tile_Folder_Path)) { Directory.CreateDirectory(Tiles_Utility.Auto_Tile_Folder_Path); } //create the final directory for the generated Images if (!Directory.Exists(Tiles_Utility.final_image_folder_path)) { Directory.CreateDirectory(Tiles_Utility.final_image_folder_path); } //create the folder for that specific file image string fileName = Path.GetFileNameWithoutExtension(path); string loaded_file_image_path = string.Format(@"{0}/_{1}", Tiles_Utility.final_image_folder_path, fileName); //ex rtp_import\Outside_A2\single_block_folder\final_tile\Image if (!Directory.Exists(loaded_file_image_path)) { Directory.CreateDirectory(loaded_file_image_path); } List <string> images_path = new List <string>(); //list of the path of the impoted tiles Dictionary <byte, int> rule_tiles = new Dictionary <byte, int>(); //dictionary for the tile rules //foreach sub pieces in the image for (int sub_block_count = 0; sub_block_count < sub_blocks.Count; sub_block_count++) { if (!sub_blocks_to_import[sub_block_count]) { continue; //If the current sub is not selected to process than skip it } int tiles_counter = 0; // counter to enumerate the sprite Texture2D sub_piece = sub_blocks[sub_block_count]; //get the texture //temp array to store the sub mini tiles Texture2D[] bottom_left_mini_tiles, bottom_right_mini_tiles, top_left_mini_tiles, top_right_mini_tiles; //generate the mini tiles to the following computation RPGM_XP_Utility.Generate_Mini_Tile_RPGMXP(sub_piece, mini_tile_w, mini_tile_h, out bottom_left_mini_tiles, out bottom_right_mini_tiles, out top_left_mini_tiles, out top_right_mini_tiles); Texture2D sprite_tiles = new Texture2D(wBlock * 8, hBlock * 6); int sprite_tile_width = wBlock * 8; string sprite_sheet_path = string.Format(@"{0}/_{1}_{2}.png", loaded_file_image_path, Path.GetFileNameWithoutExtension(path), sub_block_count); //generate and iterate the final tile for the subs pieces foreach (KeyValuePair <byte, Texture2D> kvp in RPGM_XP_Utility.Generate_Final_Tiles_RPGMXP(mini_tile_w, mini_tile_h, bottom_left_mini_tiles, bottom_right_mini_tiles, top_left_mini_tiles, top_right_mini_tiles, rule_tiles)) { int xx = tiles_counter % 8 * wBlock; int yy = tiles_counter / 8 * hBlock; sprite_tiles.SetPixels(xx, sprite_tiles.height - yy - hBlock, wBlock, hBlock, kvp.Value.GetPixels()); tiles_counter++; } images_path.Add(sprite_sheet_path); File.WriteAllBytes(sprite_sheet_path, sprite_tiles.EncodeToPNG()); AssetDatabase.Refresh(); TextureImporter importer = AssetImporter.GetAtPath(sprite_sheet_path) as TextureImporter; if (importer != null) { importer.textureType = TextureImporterType.Sprite; importer.spriteImportMode = SpriteImportMode.Multiple; importer.filterMode = FilterMode.Point; importer.spritePixelsPerUnit = hBlock; importer.compressionQuality = 0; importer.maxTextureSize = sprite_tile_width; SpriteMetaData[] tmps = new SpriteMetaData[8 * 6]; string tmpName = Path.GetFileNameWithoutExtension(sprite_sheet_path); for (int i = 0; i < 48; i++) { int xx = i % 8 * wBlock; int yy = (i / 8 + 1) * hBlock; SpriteMetaData smd = new SpriteMetaData(); smd = new SpriteMetaData(); smd.alignment = 0; smd.border = new Vector4(0, 0, 0, 0); smd.name = string.Format("{0}_{1:00}", tmpName, i); smd.pivot = new Vector2(.5f, .5f); smd.rect = new Rect(xx, sprite_tiles.height - yy, wBlock, hBlock); tmps[i] = smd; } importer.spritesheet = tmps; importer.SaveAndReimport(); } } AssetDatabase.Refresh(); //refresh asset database //generate the A2_tile Auto tiles for (int i = 0; i < images_path.Count; i += 1) { string str = images_path[i]; Tiles_A2_Utility.Generate_A2_Tile_SS(path, str, rule_tiles); } }
/// <summary> /// Generate the selected water tile /// </summary> /// <param name="path"></param> /// <param name="sub_blocks_water"></param> /// <param name="sub_blocks_water_to_import"></param> /// <param name="mini_tile_w"></param> /// <param name="mini_tile_h"></param> /// <param name="wBlock"></param> /// <param name="hBlock"></param> /// <param name="generate_sprite_sheet_image"></param> public override void Generate_Water_Tiles(string path, List <Texture2D> sub_blocks_water, List <bool> sub_blocks_water_to_import, int mini_tile_w, int mini_tile_h, int wBlock, int hBlock, bool generate_sprite_sheet_image) { //create the final directory for the auto tile if (!Directory.Exists(Tiles_Utility.Auto_Tile_Folder_Path)) { Directory.CreateDirectory(Tiles_Utility.Auto_Tile_Folder_Path); } //create the final directory for the generated Images if (!Directory.Exists(Tiles_Utility.final_image_folder_path)) { Directory.CreateDirectory(Tiles_Utility.final_image_folder_path); } //create the folder for that specific file image string fileName = Path.GetFileNameWithoutExtension(path); string loaded_file_image_path = string.Format(@"{0}/_{1}", Tiles_Utility.final_image_folder_path, fileName); //ex rtp_import\Outside_A2\single_block_folder\final_tile\Image if (!Directory.Exists(loaded_file_image_path)) { Directory.CreateDirectory(loaded_file_image_path); } List <string> images_path = new List <string>();//list of the folder of the imported tiles Dictionary <byte, int> rule_tiles = new Dictionary <byte, int>(); //foreach sub pieces in the image. If it's an animated auto tile 3 consecutive sub blocks are 3 frame of the animation for (int sub_block_count = 0; sub_block_count < sub_blocks_water_to_import.Count; sub_block_count++) { //If the current sub is not selected to process than skip it if (!sub_blocks_water_to_import[sub_block_count]) { continue; } for (int i = sub_block_count * 4; i < sub_block_count * 4 + 4; i++) { int tiles_counter = 0; //set zero to che final tile counter Texture2D sub_piece = sub_blocks_water[i]; //temp array to store the sub mini tiles Texture2D[] bottom_left_mini_tiles, bottom_right_mini_tiles, top_left_mini_tiles, top_right_mini_tiles; //generate the mini tiles to the following computation RPGM_XP_Utility.Generate_Mini_Tile_RPGMXP(sub_piece, mini_tile_w, mini_tile_h, out bottom_left_mini_tiles, out bottom_right_mini_tiles, out top_left_mini_tiles, out top_right_mini_tiles); int wb = 8, hb = 7; Texture2D sprite_tiles = new Texture2D(wBlock * wb, hBlock * hb); int sprite_tile_width = Mathf.Max(wBlock * wb, wBlock * hb); string sprite_sheet_path = string.Format(@"{0}/_Water_{1}_{2}.png", loaded_file_image_path, Path.GetFileNameWithoutExtension(path), i); //generate and iterate the final tile for the subs pieces foreach (KeyValuePair <byte, Texture2D> kvp in RPGM_XP_Utility.Generate_Final_Tiles_RPGMXP(mini_tile_w, mini_tile_h, bottom_left_mini_tiles, bottom_right_mini_tiles, top_left_mini_tiles, top_right_mini_tiles, rule_tiles)) { int xx = tiles_counter % 8 * wBlock; int yy = tiles_counter / 8 * hBlock; sprite_tiles.SetPixels(xx, sprite_tiles.height - yy - hBlock, wBlock, hBlock, kvp.Value.GetPixels()); tiles_counter++; } images_path.Add(sprite_sheet_path); File.WriteAllBytes(sprite_sheet_path, sprite_tiles.EncodeToPNG()); AssetDatabase.Refresh(); TextureImporter importer = AssetImporter.GetAtPath(sprite_sheet_path) as TextureImporter; if (importer != null) { importer.textureType = TextureImporterType.Sprite; importer.spriteImportMode = SpriteImportMode.Multiple; importer.filterMode = FilterMode.Point; importer.spritePixelsPerUnit = hBlock; importer.compressionQuality = 0; importer.textureCompression = TextureImporterCompression.Uncompressed; importer.maxTextureSize = sprite_tile_width; SpriteMetaData[] tmps = new SpriteMetaData[wb * hb]; string tmpName = Path.GetFileNameWithoutExtension(sprite_sheet_path); for (int j = 0; j < hb * wb; j++) { int xx = j % 8 * wBlock; int yy = (j / 8 + 1) * hBlock; SpriteMetaData smd = new SpriteMetaData(); smd = new SpriteMetaData(); smd.alignment = 0; smd.border = new Vector4(0, 0, 0, 0); smd.name = string.Format("{0}_{1:00}", tmpName, j); smd.pivot = new Vector2(.5f, .5f); smd.rect = new Rect(xx, sprite_tiles.height - yy, wBlock, hBlock); tmps[j] = smd; } importer.spritesheet = tmps; importer.SaveAndReimport(); } } } AssetDatabase.Refresh(); //refresh asset database //generate the fixed Auto tiles for (int i = 0; i < images_path.Count; i += 4) { RPGM_XP_Utility.Generate_Water_Tile_SS(path, images_path[i], images_path[i + 1], images_path[i + 2], images_path[i + 3], rule_tiles, wBlock); } }