Unity provides Chettu for the 2D Sprite, currently the latest version of the 5.2.2 offers three ways:
Automatic
Grid by Cell Size
Grid by Cell Count
According to the principle should be satisfied with a variety of plot, but if we have a pure and transparent elements of the diagram, and we need to take the map by number, then unity Chettu will be slightly more than transparent elements of intelligence, the following figure
We want to cut it evenly into 12*12 squares, and from top to bottom, numbered 0 to 143.
Using Unity's Chettu algorithm automatically skips over the transparent lattice, causing our numbering to be misplaced.
I did not find a good solution, so I can only write a tool, the middle also found a unity of small bug~
We have the Unity Editor metadata operations related tool functions to write:
Using Unityengine;
Using Unityeditor;
Using System.Collections;
Using System.IO;
Using System.Collections.Generic;
Using Jianghux;
Using Unityeditorinternal;
Using Unityeditor.animations; public class Spritetools:editor {[MenuItem (' tools/tilemaptools/processtileresources ')] public static void Processtile
Resources () {Debug.Log ("Processing Explore map Picture ...");
Process ("Dixiachengzhuanshitudi");
Process ("Dixiachengwupin");
Process ("Caoshuituhunhe");
Process ("Dixiachengdituheji");
Process ("Shanmaichengshi", 256, 256);
Process ("Shulin");
Process ("teshudixing");
Process ("Tudiheji");
Process ("Shibanwenli", 512, 256);
Process ("Jianzhu"); private static void Process (string file, int sizew = 128, int sizeh = 128) {Texture2d SP = Resources.load<textu
Re2d> ("tileres/" + file);
int W = Sp.width;
int H = Sp.height;
int ROW = H/sizeh;
int COLUMN = W/sizew;
String path = "Assets\\resources\\tileres\\" + file + ". png"; Debug.Log ("Processing tile resource: "+ path);
Textureimporter textureimporter = Assetimporter.getatpath (path) as Textureimporter;
var blocks = new Spritemetadata[column * ROW];
for (int i=0;i<row;++i) {for (int j=0;j<column;++j) {int id = i*column + j;
Spritemetadata tmp = new Spritemetadata ();
Tmp.name = File + "_" + ID;
Tmp.rect = new Rect (J*sizew, Row*sizeh-sizeh-i * Sizeh, Sizew, Sizeh);
Blocks[id] = tmp;
} textureimporter.spritesheet = Blocks;
Textureimporter.fadeout =!textureimporter.fadeout;
Textureimporter.saveandreimport ();
SB Unity ' s bug (force refresh) Textureimporter.fadeout = false;
Textureimporter.saveandreimport ();
}
}
This is divided evenly according to the size of the image provided. Finally unity has a bug is textureimporter in the case of only modifying Spritesheet members, Saveandreimport () is invalid (it is estimated that it is not marked as dirty), but there is no way, only use a stupid way, Find one of the other member functions to smear it, save it, and then paint it back. (Looking for fadeout here)