Here's a quick guide to the basics of creating a multi-sprite image and importing it into Unity.
**Create the image**
I use Gimp for this, but any decent 2D art tool should be fine.
Start with a totally-transparent image. Draw your various sprites in non-overlapping regions on top of the transparency. You can lay them out however you like, it doesn't matter if you leave huge gaps between the sprites for now, and you don't have to align them to a grid or anything like that if you don't want to.
Save the final image as a PNG or some other file format that supports transparency and is understood by Unity.
**Set up the sprite sheet in Unity**
Select the image in the Project tab in Unity, then look in the Inspector. Set its "Texture Type" to "Sprite", and then set its "Sprite Mode" to "Multiple". Then press the "Sprite Editor" button that appears a few options lower in the Inspector.
In the sprite editor, press the "Slice" button in the top left corner. The default options are pretty good - it will automatically figure out which parts of the image correspond to distinct sprites. You can then click on a region to select it, and give it a name using the pop-up box in the lower right corner of the sprite editor. You can also move the box around, to add padding around the sprite, or to make it be a fixed size and to ensure that your graphics are centred correctly.
When you're done, press the "Apply" button in the top right of the sprite editor window. Now in the Project tab you can expand your sprite sheet out, and see the "child" sprites. You then use the child sprites just as if they were separate image files in the first place, e.g. by dragging them into the 2D view to create Sprite gameobjects.
**Grid slicing**
An alternative you should be aware of is using grid slicing. This works well if your sprites are all a fixed size, e.g. 64x64. You can then draw them in properly-aligned grid cells in your art tool, and Unity will slice your spritesheet according to the size you specify, instead of trying to fit boxes around non-transparent regions.
**Layers**
Another powerful option is to draw your sprites on separate layers in your 2D art tool. This can help you preview animation, as you can easily swap between frames. You can then use an export plugin to arrange the separate layer images into a single sprite sheet. You can also bypass the sprite sheet entirely here, and treat the layers as separate images in your game. Unity can create its own sprite sheet automatically at export time, out of your separate image files or PSD layers. It's up to you whether you'd prefer to lay it out yourself or let Unity do it, but it's good to be aware of the option.
↧