If you get a full picture, you want to use the Ngui sprite after splitting it! The requirements that can be solved below.
Steps:
1. Split a picture using Unity's Spirte
2. Use the code to convert the split 2DSpirte cost to PNG images, then import unity using Atlas texture O (∩_∩) o~
Precautions:
1. Switch the image to the advanced type Read/write enabled hook, otherwise it will throw an exception
Directly on the code:
[MenuItem ("tools/Export Wizard")] Static voidSavesprite () {//each map type advanced Read/write enabled to make file read stringResourcespath =@"assets/resources/"; foreach(Object objinchselection.objects) {stringSelectionpath =Assetdatabase.getassetpath (obj); //must be the most superior is "assets/resources/" if(Selectionpath.startswith (Resourcespath)) {//get the file after the charge. PNG stringSelectionext =System.IO.Path.GetExtension (Selectionpath); if(Selectionext.length = =0)Continue; //Get Path "Ui/testui" from Path "Assets/resources/ui/testui.png " stringLoadPath = Selectionpath.remove (Selectionpath.length-selectionext.length); LoadPath=loadpath.substring (resourcespath.length); //load all resources under this fileSprite [] spritelist = resources.loadall<sprite>(LoadPath); if(Spritelist.length >0) { //Create an Export folder stringOutpath = Application.datapath +"/outsprite/"+LoadPath; System.IO.Directory.CreateDirectory (Outpath); foreach(varSpriteinchspritelist) {texture2d Tex=NewTexture2d ((int) Sprite.rect.width, (int) Sprite.rect.height,sprite.texture.format,false); Tex. SetPixels (Sprite.texture.GetPixels (int) Sprite.rect.xMin, (int) Sprite.rect.yMin, (int) Sprite.rect.width, (int) (sprite.rect.height)) ; Tex. Apply (); //write into a PNG fileSystem.IO.File.WriteAllBytes (Outpath +"/"+ Sprite.name +". PNG", Tex. Encodetopng ()); Debug.Log ("Savesprite to"+Outpath); } Debug.Log ("save picture Finished!"+Outpath); } } } }
Unity picture Segmentation saves Spirte on-premises