/// <summary> /// Generate the selected tiles /// </summary> /// <param name="path"></param> /// <param name="sub_blocks"></param> /// <param name="sub_blocksto_import"></param> /// <param name="wBlock"></param> /// <param name="hBlock"></param> public virtual void Generate_Tiles(string path, List <Texture2D> sub_blocks, List <bool> sub_blocksto_import, int wBlock, int hBlock) { //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 //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_to_import.Count; sub_block_count++) { //If the current sub is not selected to process than skip it if (!sub_blocks_to_import[sub_block_count]) { continue; } int tiles_counter = 0; //set zero to che final tile counter Texture2D sub_piece = sub_blocks[sub_block_count]; //save each final tile to its own image var tile_bytes = sub_blocks[sub_block_count].EncodeToPNG(); string tile_file_path = string.Format(@"{0}/_{1}_{2}_{3:000}.png", loaded_file_image_path, Path.GetFileNameWithoutExtension(path), sub_block_count, tiles_counter); images_path.Add(tile_file_path); File.WriteAllBytes(tile_file_path, tile_bytes); TextureImporter importer = AssetImporter.GetAtPath(tile_file_path) as TextureImporter; if (importer != null) { importer.textureType = TextureImporterType.Sprite; importer.spriteImportMode = SpriteImportMode.Single; importer.filterMode = FilterMode.Point; importer.spritePixelsPerUnit = hBlock; importer.compressionQuality = 0; importer.maxTextureSize = wBlock; importer.SaveAndReimport(); } tiles_counter++; } AssetDatabase.Refresh(); //refresh asset database //generate the fixed Auto tiles for (int i = 0; i < images_path.Count; i++) { Tiles_A5_Utility.Generate_A5_Tile(path, images_path[i]); } }