---restore content starts---
Ngui Atlas decomposition of Unity3d generic tool class
Because of the recent need for some art resources, but I do not make the UI, so I would like to go to the online project directly to find a few available mapping resources.
However, it was found that these resources have been packaged with Ngui's packaged Atlas tool, and the original small map has all been deleted, leaving only one prefab.
So what does this prefab contain:
1. A large Atlas Map
2. Large texture of the material ball
3. Hang up the Uiatla script of the precast material
So the point is, how do we get the little stickers in this big map?
Here I wrote a small plug-in, I directly in the Ngui source code inside Change:
Find the source code for Ngui: Uiatlasmaker
In the Ongui method, I added a new code to export the map:
Guilayout.beginhorizontal (); { if (Tex! = null) { if (Guilayout.button ("Export map (PNG)", Guilayout.width (120f))) { string FilePath = Editorutility.savefolderpanel ("Save map to specified folder", "", ""); Exporttexturepngfromatlas (FilePath, Nguisettings.atlas); }} Guilayout.endhorizontal ();
Exporttexturepngfromatlas ():
static void Exporttexturepngfromatlas (String Folderpath,uiatlas Atlas) {list<uispritedata> Exitsprite SList = atlas.spritelist; Texture2d atlastexture = Nguieditortools.importtexture (Atlas.texture, True, false,!atlas.premultipliedalpha); int oldwith = Atlastexture.width; int oldheight = Atlastexture.height; color32[] oldpixels = null; foreach (var es in exitspriteslist) {int xmin = Mathf.clamp (es.x, 0, Oldwith); int ymin = Mathf.clamp (es.y, 0, OldHeight); int newwidth = Mathf.clamp (es.width, 0, Oldwith); int newheight = Mathf.clamp (es.height, 0, OldHeight); if (Newwidth = = 0 | | newheight = = 0) continue; if (oldpixels = = null) Oldpixels = ATLASTEXTURE.GETPIXELS32 (); color32[] Newpixels = new color32[newwidth * Newheight]; for (int y = 0, y < newheight; ++y) {for (int x = 0; x < newwidth; ++x) {int newindex = (newHeight-1-y) * newwidth + x; int oldindex = (OldHeight-1-(ymin + y)) * Oldwith + (xmin + x); Newpixels[newindex] = Oldpixels[oldindex]; }} texture2d t = new Texture2d (newwidth, newheight); T.SETPIXELS32 (Newpixels); T.apply (); byte[] bytes = T.encodetopng (); Texture2d.destroyimmediate (t); t = null; if (! Directory.Exists (FolderPath)) {directory.createdirectory (FolderPath); } using (FileStream fs = new FileStream (FolderPath + "/" + Es.name + ". png", filemode.createnew)) { BinaryWriter writer = new BinaryWriter (FS); Writer. Write (bytes); } } }
Open the Ngui Atlas Maker:
Click the export map, then pop up the selection to save the map to which folder, click Select Folder, the small map is exported successfully.
Ngui Atlas decomposition of Unity3d generic tool class