Unity Cut Export Wizard

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.