[Free Asset] Simple Sprite Packer

Hey guys,

Since the integrated sprite packer is for the pro version only i have decided to write my own little sprite packer to ease my workflow and so i decided to share it with the community. It’s really simple and easy to use.

I haven’t yet tested it fully but i hope you guys post some feedback and maybe some improvement suggestions.

Open in the Asset Store

It’s features include:

  • MaxRects packing method.
  • Unity packing method.
  • Separate Drag and Drop window.
  • Texture resource packing.
  • Sprite resource packing.
  • Sprite data transfer.
  • Action queue.
  • Source sprite reference replacing tool.

Changelog:

  • Version 1.7

  • Source sprite reference replacing tool will now also set the values of structs.

  • Source sprite reference replacing tool will now target only prefabs if the target is Project.

  • Version 1.6

  • Greatly improved source sprite reference replacing speed.

  • Version 1.5

  • Extended the source sprite reference replacing tool.

  • Version 1.4

  • Added source sprite reference replacing tool.

  • Version 1.3

  • Simple Sprite Packer no longer prevents building.

  • Version 1.2

  • Improved MaxRects packing performance be pre-estimating the texture size (Provided by Vrvyus).

  • Version 1.1

  • Fixed packing issue when the source is Sprite of type Multiple.

  • Inspector will no Repaint when settings are changed in the SPSettings window.

3 Likes

This is pure awesomeness :slight_smile:

my feedback:

  • multiselect of sprites would be nice,
  • I sometimes get an error when adding several sprites:
Array size must be at least width*height
UnityEngine.Texture2D:SetPixels(Color[])
SimpleSpritePacker.SPInstance:RebuildAtlas() (at Assets/Simple Sprite Packer/SPInstance.cs:459)
SimpleSpritePackerEditor.SPInstanceEditor:smile:rawActionButtons() (at Assets/Simple Sprite Packer/Editor/SPInstanceEditor.cs:90)
SimpleSpritePackerEditor.SPInstanceEditor:OnInspectorGUI() (at Assets/Simple Sprite Packer/Editor/SPInstanceEditor.cs:58)
UnityEditor.DockArea:OnGUI()

thanks

Edit:
I just modified SPInstance.cs:458 to

Color[] pixels = sourceSprite.texture.GetPixels( 0, 0, texture.width, texture.height );

so it copies non-trimmed sprite.

1 Like

If you are importing a sprite that is part of sprite collection (Atlas) you’ll copy the whole texture and not just the sprite you are importing.

I think i tracked down the problem, you can re-download the package and test it out.

After reading the documentation of SetPixels i noticed the texture we are setting the pixels must be ARGB32 format and in the script i did not specified the TextureFormat… So i think that was the problem.

Edit: When i think of it, it might be the GetPixels that’s failing and not the SetPixels…
Edit again: Might be cause i used Sprite.rect for the new texture size and Sprite.textureRect for the pixel extraction…
Edit again: It’s been fixed, Sprite.textureRect was the problem and the fix was to use Sprite.rect instead.

1 Like

Wow this is great work ChoMPi! This deserves more eyeballs :slight_smile:

1 Like

It works great now :slight_smile:
I added atlas size estimation in UITexturePacker.cs. It makes it a tiny bit faster for larger atlases.

    public static Rect[] PackTextures (Texture2D texture, Texture2D[] textures, int padding, int maxSize)
    {
        int area = 0;
        for ( int i = 0; i < textures.Length; i++ )
        {
            Texture2D tex = textures[i];
            area += tex.width * tex.height;
        }
        int startW = 4;
        int startH = 4;
        while ( startW * startH < area )
        {
            if ( startW <= startH ) startW *= 2;
            else startH *= 2;
        }
        if ( startW > maxSize || startH > maxSize ) return null;

        return PackTextures( texture, textures, startW, startH, padding, maxSize );
    }
1 Like

Another feature that would be nice. Option for RGB (opaque) texure atlas. :slight_smile:

Edit: nevermind, you can just change compression of the atlas :slight_smile:

Do you mean applying a background to each sprite in the atlas ?

I just realized that the Sprite Packer is preventing projects from building, gonna have to move some thing around to fix it…

If you move all the files in Editor subfolder, it works.

My Unity is crashing every time I try to create a Sprite Packer, I’m using it on Mac btw.

Just a question though, let’s say I have a texture with 4 sprites, when I create the atlas using this tool, will the Sprite Renderers reference the sprites on the new atlas? without me having to do it manually?

A. I dont have access to a Mac, maybe you could post the Editor.log from the crash?
B. No, currently it does not replace references… But i could script that real easy : ]

Tried on imac, works for me… (with older unity4.5.0)

Just uploaded v1.4 with a Source Sprite Reference Replacing Tool : ]

I tested it on another machine and it worked perfectly. That replacing tool is amazing, but is it possible to replace the sprites in all scenes? or let the user choose the scenes? Because atm is either the current scene or the project, and in a project like mine which has a lot of scenes (100+), I have to go through all of them and use the replace tool.

What an awesome tool you just created!

1 Like

Well, the contents of the scene are not available till the scene is loaded, so maybe if i made the tool load each scene and replace the sprites it could work… I’ll give it a try today. : ]

It’s done, you can re-download the sprite packer package and test it out.
It takes the enabled scenes in the build settings.

And now in the Asset Store!

I get error

Assets/Simple Sprite Packer/Scripts/Editor/SPAtlasBuilder.cs(195,63): error CS1501: No overload for method PackTextures' takes 4’ arguments

I got it too, please fix :slight_smile: