Need help packing menu textures

I have a menu that is essentially a background image and 4 buttons using GUITextures. What I’m trying to do is get the buttons into one draw call.

My idea is to use the PackTextures() function to create an atlas, but I need help! I’m unfamiliar with non-runtime code and was wondering if someone could give me the basics of how I’d go about replacing my buttons into one atlas and getting them back into the scene?

I’m thinking something along the lines of…

  1. Create temporary GameObject
  2. Attach the button textures as an array
  3. Run PackTextures() function on array to create atlas
  4. Delete/disable the temp GameObject
  5. Find the resulting atlas [where?] and attach it to all 4 buttons
  6. Get the rect coordinates [how?]
  7. Specify the rect coordinates to each GUITexture component so it knows which area of atlas to use [also how?]

Hm, I don’t think you can change the UV mapping of GUITextures, you might need to use UnityGUI instead (the stuff in OnGUI(), although I’m also not sure it’s possible with that, either, since I don’t use it), or use a planar 3D object attached to your camera parallel to your screen (there are scripts around on how to accomplish that)

But to answer the rest of your questions:

  • 1+4 You don’t need an additional GameObject, just attach the script to an empty object, or your target object
  • 5 PackTextures() is a method of Texture2D, and the resulting atlas will replace that texture. So for example, you could create an empty texture, call myTexture.PackTextures() on it, and now myTexture will be your atlas
  • 6 The Rect array matching your Texture2D input array is returned by PackTextures()