Show portion of texture in GUI?

Is there a way to have 1024 x 1024 texture but only show a portion through a GUI command?

As example a texture with 20 button images and I show one of the images in a button command without showing the others.

Thanks.

GUI.BeginGroup and GUI.EndGroup() sets up a little virtual viewport, controlling where GUI operations are clipped. With good use of this, you can definitely draw sections of textures.

Wow. Dont try to use GUI for that unless you really, really want to kill performance. Either use one of the sprite atlas scrips on the forum or make your own mesh and adjust the verts/UV’s in code to map things the way you want.

Is there a reference or tutorial somewhere to get a heads up on how to do this?

Thanks.

Check out the source code to any of the sprite managers (SpriteManager, GUISpriteUI, EZGUI, etc.). They all do what you are looking for.

:smile:

Using this technique now… for a quick and dirty… gets the job done. : )

At some point down the road I will definitely have to man up and jump into the other techniques.

Thanks.

I have to say… using two large textures for all the gui stuff is really fast and convenient.

Example:
One texture for all buttons up and one texture for all buttons down. This is super fast in photoshop, the logistics of only 2 image files instead of 40, you only have to code call 2 files instead of 40, you call different buttons just by calling different locations on the map, if you use the same size for each image you can use math for the calling of the button images, and this is saving me a butt load of memory.

So far thumbs up on this approach from me.

Thanks.

Yes, that is convenient, indeed. IMHO, it is even more convenient IMHO to be able to throw multiple individual files into a single atlas automatically (which SM2 and EZ GUI do), allowing your elements to batch together. The problem with using Unity GUI class is you’re going to get a whole draw call for each control. So if you have 5 buttons, you’re going to generate 5 draw calls. If you have some text on top of that, you get another draw call for each piece of text. It can add up really fast and eats a lot of performance. Which is why, for iPhone, I recommend using a sprite-based approach for GUIs, as sprites which share a single atlas/material can batch together for a single draw call. Same goes for 3D Text/TextMesh components.