"Reprint" uses Unity's own graph cutting function to cut the graphs into sub-graphs

Source: Internet
Author: User

Although there are many tools on the Internet to cut the graph function, but most of them are automatically cut or according to the plist files,

This kind of cutting is often not self-tuning or difficult to adjust, resulting in unsatisfactory results.

Today Stroll Bar found a netizen wrote the cut diagram plugin is very good, share the next,

The use of unity with the graph cutting function, the original cutting function although very convenient and easy to fine-tune, but can not be exported, the netizen exported them,

From: Baidu Unity3d paste 13471713164

Links: http://tieba.baidu.com/p/3217039693

usingUnityengine;usingUnityeditor;usingSystem.Collections.Generic;usingSystem.IO;/// <summary>///You can export the image of the unity-in-the-picture cut function to a sub-graph///How to use:///1. Import PNG map First///2. Picture texture type to select Advanced and the following read/wite enable to tick///3. Set the picture format to "Mult", and click "Editor" to start cutting the image.///4. After the cut is finished, select the picture, click Process to sprites and then you can export/// </summary> Public Static classspritesheetpackerimport{[MenuItem ("assets/sprite Sheet packer/process to Sprites")]    Static voidProcesstosprite () {texture2d image= Selection.activeobject astexture2d;//gets the rotated object        stringRootPath = Path.getdirectoryname (Assetdatabase.getassetpath (image));//Get path name        stringPath = RootPath +"/"+ Image.name +". PNG";//Picture path nameTextureimporter Teximp= Assetimporter.getatpath (path) asTextureimporter;                               Assetdatabase.createfolder (RootPath, image.name); //Create a folder        foreach(Spritemetadata MetaDatainchTeximp.spritesheet)//traversing small atlas{texture2d MyImage=NewTexture2d ((int) MetaData.rect.width, (int) metaData.rect.height); //abc_0: (x:2.00, y:400.00, width:103.00, height:112.00)             for(inty = (int) Metadata.rect.y; Y < Metadata.rect.y + metaData.rect.height; y++)//y-axis pixels            {                 for(intx = (int) Metadata.rect.x; X < Metadata.rect.x + metaData.rect.width; X + +) MyImage. SetPixel (x- (int) Metadata.rect.x, Y-(int) Metadata.rect.y, image.            GetPixel (x, y)); }            //convert textures to encodetopng compatible format            if(Myimage.format! = Textureformat.argb32 && Myimage.format! =textureformat.rgb24) {texture2d newtexture=Newtexture2d (Myimage.width, myimage.height); Newtexture.setpixels (myimage. Getpixels (0),0); MyImage=newtexture; }            varPngdata =MyImage.            Encodetopng (); //Assetdatabase.createasset (myimage, RootPath + "/" + Image.name + "/" + Metadata.name + ". PNG ");File.writeallbytes (RootPath +"/"+ Image.name +"/"+ Metadata.name +". PNG", Pngdata); }    }}

"Reprint" uses Unity's own graph cutting function to cut the graphs into sub-graphs

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.