public static Rect[] rebuildAtlas( Texture2D[] textures, string filename, bool generateSdAtlas )
{
var texture = new Texture2D( 0, 0, TextureFormat.ARGB32, false );
var rects = texture.PackTextures( textures, atlasPadding, 4096 );
// if generateSdAtlas is true, we make 2 atlases one being half the size of the source images
var sourceAtlasFilename = filename + ( generateSdAtlas ? "@2x" : string.Empty );
saveAtlasPng( defaultAtlasResourcesPath, sourceAtlasFilename, texture );
// save a half sized version as well if required
if( generateSdAtlas )
{
var sourcePath = Path.Combine( defaultAtlasResourcesPath, filename + "@2x.png" );
var destPath = Path.Combine( defaultAtlasResourcesPath, filename + ".png" );
var sdTexture = resizeTexture( sourcePath, texture.width / 2, texture.height / 2, destPath );
saveAtlasPng( defaultAtlasResourcesPath, filename, sdTexture );
GameObject.DestroyImmediate( sdTexture );
}
GameObject.DestroyImmediate( texture );
Resources.UnloadUnusedAssets();
return rects;
}