How do I scale GUI object for retina display if they are not in OnGUI?

Currently my scene has GUITextures as object, created from the GameObject menu, not dynamically generated in OnGui.

The problem with this is that the code for bumping assets up to retina size, only works on GUIText / GUITextures generated in OnGui and not GUIText / GUITextures that are from the GameObjects menu.

How can I make it so any GUI element in my scene will use the Matrix4x4.identity.Scale command?

GUITexture is resolution-independent provided you use the Transform to position and scale instead of the pixelInset rectangle.

heres the retina code that works when GUI objects are built inside it

function OnGUI() {
	var screenScale: float = Screen.width / 320.0;
	var scaledMatrix: Matrix4x4 = Matrix4x4.identity.Scale(Vector3(screenScale,screenScale,screenScale));
	GUI.matrix = scaledMatrix;
	GUI.Label( Rect( 0, 0, 480, 20 ), "test");
}

I ended up doing this

var scaleChanger:int=2;
if(Screen.width == 1024) {
//if not retina scale all gui by 50%
GUIUtility.ScaleAroundPivot(Vector2.one * 0.5, Vector2.zero);
scaleChanger=1;
}

scaleChanger was used to correct some weird positioning issues on non-retina displays. eg

GUI.BeginGroup(Rect(Screen.width/scaleChanger- (postingBG.width)/2,Screen.height/scaleChanger-(postingBG.height)/2,(postingBG.width),(postingBG.height) ));

All my GUITexture and GUIText elements are built and positioned around a 1024 x 768 display and they are intended to scale in proportion to the screen rather than to stay at the same size across all screens. This allows me to keep using pixelInset and to avoid messing with Transform scaling, which simplifies things somewhat. With my base resolution at 1024x768 it’s pretty easy to re-scale everything for other resolutions, including Retina displays. In my Globals class I define this class method:

public static void AdjustGUISizes(float ratio) {
	if (ratio != 1f) {

		foreach (GUITexture b in FindObjectsOfTypeAll(typeof(GUITexture))) {
			Rect i = b.pixelInset;
			i.x *= ratio; i.y *= ratio; i.width *= ratio; i.height *= ratio;
			b.pixelInset = i;
		}

		foreach (GUIText tx in FindObjectsOfTypeAll(typeof(GUIText))) {
			float fontRatio = ratio; if (fontRatio < 0.85f) fontRatio = 0.85f;
			tx.fontSize = (int)(tx.fontSize * fontRatio);
			tx.pixelOffset *= ratio;
		}

	}
}

And then I call it like so:

pixelRatio = Screen.width / 1024.0f;
Globals.AdjustGUISizes(pixelRatio);

Note that all of this applies to old-style GUI elements, which are now deprecated in favor of the new Canvas-based GUI system. And furthermore, this isn’t set up (as it is) for dynamic scaling as the dimensions change (such as you get with a resizable window). Plus, while FindObjectsOfTypeAll is useful for this, it is slow. It would be faster to cache the list of elements and work from that if dynamic resize is needed.

So consider this as a helpful note for maintainers of legacy code, or for historic interest.