Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to make a texture atlas via code?

Discussion in 'Scripting' started by PhilliamApps, Sep 16, 2012.

  1. PhilliamApps

    PhilliamApps

    Joined:
    Mar 13, 2011
    Posts:
    64
    So I have heard about using Texture2d.PackTextures() to make a texture atlas, and I know how the concept works. I am confused, however on how to use the rects from the function and substitute it in the textures used throughout the game. Could anyone point me in the right direction or help me out?


    Thanks guys!
     
  2. BlackMantis

    BlackMantis

    Joined:
    Feb 7, 2010
    Posts:
    1,475
    Did you search the forum? I remember there being a topic about this with example scripts in the showcase. Also there is a Asset Store product that is suppose to replace(be better than lol) the combine mesh script that creates a texture atlas and reduces draw calls at the same time.
     
  3. PhilliamApps

    PhilliamApps

    Joined:
    Mar 13, 2011
    Posts:
    64
    Thanks Black for replying. Yeah I've looked but I haven't found anything... and everything on the asset store costs money.
     
  4. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,204
  5. PhilliamApps

    PhilliamApps

    Joined:
    Mar 13, 2011
    Posts:
    64
    Thanks! So I got that set up with the rects of the different images on the atlas being returned... but how do I assign them to the different gameObjects?
     
  6. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,204
    The workflow goes like this:

    PackTextures
    Reassign UV coordinates (multiply the original uv by the new uv width and add the uv start)
    Create a new material, assign the atlas to the material
    Assign the new material to model.


    Here's a big discussion on it:

    http://forum.unity3d.com/threads/6699-Texture2D.PackTextures