Using small Rect of a Texture.

I’m overlaying icons on buttons, and currently have them as separate 32x32 textures. Ideally I want to combine them into one texture page, and be able to get the 32x32 rect I want from that texture.
I’m using this texture as an argument in GUI.Button.

This is similar to “UV animated tiles” script, but I don’t have any UVs to offset. Closest thing I can find is GUI Texture and Pixel Inset, but can’t get anything working. I’ve not seen any Texture2D and Rect examples / documentation that help either.

Is there anyway to do something like-
Texture2D newtexture = cliptexture(thebigtexture, rect(0,0,32,32))

Thanks in advance.

You can use Texture2D.GetPixels to get a rectangular area from a texture. You can then create a new Texture2D of the same size and use the complementary SetPixels function to store the pixel data:-

var tex: Texture2D;
   ...

var pixData = tex.GetPixels(xPos, yPos, blockWidth, blockHeight);
var newTex = new Texture2D(blockWidth, blockHeight);
newTex.SetPixels(pixData);
newTex.Apply();