How to make a texture atlas via code?

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!

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.

Thanks Black for replying. Yeah I’ve looked but I haven’t found anything… and everything on the asset store costs money.

You might want to do it manually if you have special needs (recoloring with shaders, bumpmaps, etc)

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?

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