Cut graphs into sub-graphs using Unity's own graph cut function

Source: Internet
Author: User

Reproduced, the cattle are everywhere, I am too small

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

1 usingUnityengine;2 usingUnityeditor;3 usingSystem.Collections.Generic;4 usingSystem.IO;5 6 /// <summary>7 ///You can export the image of the unity-in-the-picture cut function to a sub-graph8 ///How to use:9 ///1. Import PNG map FirstTen ///2. Picture texture type to select Advanced and the following read/wite enable to tick One ///3. Set the picture format to "Mult", and click "Editor" to start cutting the image. A ///4. After the cut is finished, select the picture, click Process to sprites and then you can export - /// </summary> -  Public Static classSpritesheetpackerimport the { -[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 name A  at  -Textureimporter teximp = assetimporter.getatpath (path) asTextureimporter; -  -  -Assetdatabase.createfolder (RootPath, image.name);//Create a folder -  in  -         foreach(Spritemetadata MetaDatainchTeximp.spritesheet)//traversing small atlas to         { +Texture2d myimage =NewTexture2d ((int) MetaData.rect.width, (int) metaData.rect.height); -  the  *             //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 pixelsPanax Notoginseng             { -                  for(intx = (int) Metadata.rect.x; X < Metadata.rect.x + metaData.rect.width; X + +) theMyImage. SetPixel (X-(int) Metadata.rect.x, Y-(int) Metadata.rect.y, image. GetPixel (x, y)); +             } A  the  +             //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; the             } -             varPngdata =MyImage. Encodetopng ();Wuyi  the  -             //Assetdatabase.createasset (myimage, RootPath + "/" + Image.name + "/" + Metadata.name + ". PNG "); WuFile.writeallbytes (RootPath +"/"+ Image.name +"/"+ Metadata.name +". PNG", pngdata); -         } About     } $}

This code will not take effect until the asset/editor directory is added.

Based on the above steps,

In the picture set that you want to want $ right-click Sprite Sheet Packer, Process to Sprite

After that, a folder with the same Atlas file name will be generated in the same directory, with each resource of the want $ atlas.

Cut graphs into sub-graphs using Unity's own graph cut function

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.