Unity Shoebox Extract Sprites to unity format

Source: Internet
Author: User

Cut for a transparent picture


You can use the shoebox Extract Spritesfunction, drag the picture onto the Extract Sprites feature icon and the image will be automatically cut as shown in:
Click SettingsYou can set the Clusters merge sub items to False, do not merge subkeys, change the File Name to Slice##.png, and click ApplyCan. and then press SaveYou can export the cut picture. As shown in the following:
The build includes a text document that records the coordinates of the sub-graphs for each cut. In the Editor directory of Unity, add the following script: C # Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21st
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
usingSystem.Collections.Generic;
usingSystem.Reflection;
usingUnityeditor;
usingUnityengine;
usingSystem.IO;

// <summary>
Processing shoebox cut pictures to sprites
</summary>
PublicclassShoeboxextractspritesimport
{
[MenuItem ("assets/shoebox/process to Sprites")]
StaticvoidProcessextractspritestosprites ()
{
Textasset txt = selection.activeobject asTextasset;
if(txt = =NULL)
{
Debug.logerror ("must be. txt file!");
return;
}
stringAssetpath = Assetdatabase.getassetpath (TXT);
if(Path.getextension (assetpath)! =". txt")
{
Debug.logerror ("must be. txt file!");
return;
}

stringRootPath = Path.getdirectoryname (Assetpath);
stringPath = RootPath +"/"+ path.getfilenamewithoutextension (Assetpath);
Textureimporter teximp = assetimporter.getatpath (path) asTextureimporter;
if(Teximp = =NULL)
{
return;
}

Object[] args =NewObject[2] {0,0};
MethodInfo mi =typeof(Textureimporter). GetMethod ("Getwidthandheight", BindingFlags.NonPublic | BindingFlags.Instance);
Oil Invoke (Teximp, args);

var height = (int) args[1];
List<spritemetadata> sprites = Getspritemetadatas (RootPath, txt.text, height);

Teximp.spritesheet = Sprites. ToArray ();
Teximp.texturetype = Textureimportertype.sprite;
Teximp.spriteimportmode = Spriteimportmode.multiple;

Assetdatabase.deleteasset (Assetpath);
Assetdatabase.importasset (path);
}

StaticList<spritemetadata> Getspritemetadatas (stringPathstringTextintTotalheight)
{
List<spritemetadata> sprites =NewList<spritemetadata> ();
var slicename ="Slice";
var arraytxt = text. Split (', ');
var pngindex =0;
foreach(Var txtinchArraytxt)
{
var arraypoint = txt. Split ("');

intx =int. Parse (Arraypoint[arraypoint.length-2]);
inty =int. Parse (Arraypoint[arraypoint.length-1]. TrimEnd ('. '));

pngindex++;
var pngname = slicename + pngindex.tostring (). PadLeft (2,' 0 ') +". png";
var Pngpath = path +"/"+ Pngname;
Textureimporter importer = Assetimporter.getatpath (Pngpath) asTextureimporter;

if(Importer! =NULL)
{
Object[] args =NewObject[2] {0,0};
MethodInfo mi =typeof(Textureimporter). GetMethod ("Getwidthandheight", BindingFlags.NonPublic | BindingFlags.Instance);
Oil Invoke (importer, args);

var width = (int) args[0];
var height = (int) args[1];

Spritemetadata SMD =NewSpritemetadata ();
Smd.rect =NewRect (x, totalheight-y-height, width, height);
Smd.alignment =0;
Smd.name = Pngname.remove (Pngname.length-4);
Smd.pivot =NewVector2 (0.5f,0.5f);
Sprites. ADD (SMD);

Assetdatabase.deleteasset (Pngpath);
}
}
returnSprites
}
}
In Project view, select this text document, right-click on the function shoebox→process to Sprites, and automatically complete the import into Unity Sprites format, as shown in:
Unity's Sprite Editor also comes with the ability to cut pictures, but when it comes to complex Atlas, the cut is confusing, with a shoebox accuracy ratio.
Shoebox Address: http://renderhjs.net/shoebox/

Unity Shoebox Extract Sprites to unity format

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.