Let’s say that we have a texture in multiple mode, and that gets sliced into 50 sprites.
I want to be able to have a variable of type Texture2D, set this texture (e.g. through the editor), and get all of the sprites produced by the Sprite Editor.
I can do this, by getting pixels from a texture manually, using the texture, a width, height, padding and offset, just like you enter them in the Sprite Editor’s grid slicer. Is there some better way?
for example:
Sprite GetSprite(Texture2D from, Rect rect, int atX, int atY, int paddingX, int paddingY)
{
Rect newRect = rect;
newRect.position = new Vector2((newRect.width + paddingX) * atX + newRect.position.x, (newRect.height + paddingY) * atY + newRect.position.y);
return Sprite.Create(from, newRect, Vector2.zero);
}