Unity often uses sprites, especially 2D games to make animations! Today we will learn the wizard's cutting and export it!
Needless to say, the first proposal for an empty project.
1, open Unity Build project.
2 Import footage for resource classification, engineering is not about size, this is our attitude towards it!
3. Start the Division Wizard, three steps to go!
Edit Wizard.
Start the split wizard
Apply a bit, look at the split wizard, 0-9 total 9.
Paste Wizard Export Code:
usingUnityengine;usingUnityeditor; Public classspritetailed:monobehaviour{[MenuItem ("tools/Export Wizard")] Static voidSavesprite () {stringResourcespath ="assets/resources/"; foreach(Object objinchselection.objects) {stringSelectionpath =Assetdatabase.getassetpath (obj); //must be the most superior is "assets/resources/" if(Selectionpath.startswith (Resourcespath)) {stringSelectionext =System.IO.Path.GetExtension (Selectionpath); if(Selectionext.length = =0) { Continue; } //Get Path "Sprite/number" from Path "Assets/resources/sprite/number.png " stringLoadPath = Selectionpath.remove (Selectionpath.length-selectionext.length); LoadPath=loadpath.substring (resourcespath.length); //load all resources under this filesprite[] Sprites = resources.loadall<sprite>(LoadPath); if(Sprites. Length >0) {Debug.Log (sprites. Length); //Create an Export folder stringOutpath = Application.datapath +"/outsprite/"+LoadPath; System.IO.Directory.CreateDirectory (Outpath); foreach(Sprite Spriteinchsprites) {Debug.Log ("Export Sprite:"+sprite.name); //Create a separate textureTexture2d 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 ("Savesprite finished"); }}
To hang the script on Maincamera, click tools/to Export the wizard:
Failed, check out the reason! Mo,,, Oh, now the genie is not read and write, we want to modify its properties.
Click tools/again to export the wizard, then refresh the resources, you can see!
OK, the wizard resources export successfully!
Unity Cut Export Wizard