Using with Unity GUI

I will use the same atlas as for our 3D scene, but you can experiment and create new one, using source GUI textures which is located under  Assets/Extensions/TexturePacker/Tutorial/Art/AtlasSource.

Difference between creating texture for 3D object and for GUI is, that for GUI atlases you can use Trim / Crop TexturePackre methods to save even more space (this option is available in paid version of TexturePackre)

Now we need to create our GUI drawing class. And assign it to the game object.

Here is a little overview of the function’s that’ is useful for work with the GUI part of TexturePacker extension.


To get Atlas, use:



To get Texture, use:

TPAtlas atlas = TPackManager.getAtlas(MyAtlasName);
TPAtlasTexture texture =  atlas.getTexture("myTextureName");



TPAtlasTexture texture = TPackManager.getAtlas(MyAtlasName).getPngTexture("myTextureName");


To draw Texture, use:

void OnGUI() {
    TPackManager.draw(Rect rect, string atlas, string textureName);


Here is how our AtlasGUIExample class will look like

public class AtlasGUIExample : MonoBehaviour {
    private TPAtlasTexture play;
    private Texture2D unityTexture;
    void Awake() {
        play = TPackManager.getAtlas(Atlases.EXAMPLE).getPngTexture("play");
        //Warning to Get Texture2D from atlas, should remain the same size which was generated,
        //that's why we using another atlas here
        unityTexture = TPackManager.getAtlas(Atlases.EXAMPLE2).getUnityTexture("play");

    void OnGUI() {
        play.draw(new Rect(0, 0, play.width * 0.5f, play.height * 0.5f));
        play.draw(new Rect(0, 75, play.width, play.height));

        GUI.DrawTexture(new Rect(0, 225, unityTexture.width, unityTexture.height ), unityTexture);

        TPackManager.draw(new Rect(200, 0, 122, 42), Atlases.EXAMPLE, "f_share.png");
        TPackManager.getAtlas(Atlases.EXAMPLE).draw(new Rect(200, 100, 122, 42), "t_share.png");


Proceed to the animation test (GUI animation available only in paid version)

We can use same atlas as for out 3D stage.

Let’s Create “AtlasGUIAnimationExample” class and attach it to any gameobject on the stage. Here is how it will look like.


using UnityEngine;
using System.Collections;

public class AtlasGUIAnimationExample : MonoBehaviour {

    private TPGUIAnimation anim;
    private TPGUIAnimation Scaledanim;
    void Awake() {
        anim        =  TPGUIAnimation.Create();
        Scaledanim  =  TPGUIAnimation.Create();

        for(int i = 1; i < 7; i++) {
            TPAtlasTexture frame = TPackManager.getAtlas(Atlases.EXAMPLE).getPngTexture("fireball_000" + i.ToString());

        anim.pos = new Vector2(200, 200);
        anim.loop = true;
        anim.fps = 25;


        Scaledanim.pos = new Vector2(300, 200);
        Scaledanim.loop = true;
        Scaledanim.fps = 25;
        Scaledanim.scale = 0.5f;


    void OnGUI() {




In conclusion, here are a few advantages to using this.

  • Fast and easy atlas generation

  • Easy to remove or add texture from atlas

  • Built-in animation solution

  • reduced build size

  • reduced RAM consumption

  • increased performance