Editor Script / Uncategorized

Sprite Splitter Script using TextureImporter

September 10, 2016

Tags: , , , ,

I’ve been building an editor tool for a new project I’m working on, and was playing around with different sprites to use for part of the UI. The slices in the spritesheet are mapped to a list of options in a dropdown, so instead of manually naming them each time, I wrote a small script to create the spritesheet from the list of option names.

The full code can be found on GitHub.

for (int row = maxRows - 1; row >= 0 ; row--)
for (int column = 0; column < maxColumns; column++) { if(index >= names.Length) break;
SpriteMetaData metadata = new SpriteMetaData();
metadata.alignment = 1;
metadata.name = names[index];
metadata.pivot = new Vector2(0, 1);
float posX = sliceWidth * column;
float posY = sliceHeight * row;
metadata.rect = new Rect(posX, posY, sliceWidth, sliceHeight);
importer.spritesheet = spritesheet.ToArray();



Your email address will not be published.