Hi guys, currently I have a single map that I want to split into 16x16 pixels and automatically put it (the entire thing) in the scene. I’ve been doing it manually up until now by splicing it and using a tile editor to place them together, but I’m really dying for an automatic solution. Is there a way to do this without spending money? I still want the 16x16 tiles to be considered separate game objects. Thanks
What part makes you the trouble? The splitting of images should be quite fast if you use the auto-split function of unity (clickme and scroll down until “Automatic slicing”). 20 images should take around 5-10 minutes max…
For arranging the images into the scene, you know about the grid snapping, right? (Edit/Snap settings will edit the grid size and dragging while holding down Ctrl/Command key will snap while when you move). That makes it quite easy to manually place objects in a fixed grid. Remember that you can first place all the tiles in a grid anywhere and then move/rotate them together if they are not spot-on as a group.
Remember that many functions like changing properties (like the single/multiple sprites setting) can be executed on multi-selections. You can also bulk-drag’n’drop many sprites in one go onto the scene (and then move them around row-by-row).
Check Sprite.Create
Sample would be like;
Sprite[,] TileSprites;
public int NumberOfColumns, NumberOfRows;
public Sprite SourceSprite;
void SliceImage(){
int PixelsToUnits = SourceSprite.texture.height / NumberOfRows;
TileSprites = new Sprite[NumberOfColumns, NumberOfRows];
for(int i = 0; i < NumberOfColumns; i++){
for(int y = 0; y < NumberOfRows; y++){
Rect theArea = new Rect(i * PixelsToUnits, y * PixelsToUnits, PixelsToUnits, PixelsToUnits);
TileSprites[i,y] = Sprite.Create(SourceSprite.texture, theArea, Vector2.zero, PixelsToUnits);
}
}
}
edit: the above would create square tiles, and it requires that source texture resolution is divisible by both column number and row number. You can change it accordingly to your needs.