Turns out GUI doesn't scale with different resolutions. But no matter - maths saves the day:
float tx, ty, width, height, multiplier;
multiplier = (1 / baseScreenHeight) * Screen.height;
width = g.pixelInset.width * multiplier;
tx = g.pixelInset.x * multiplier;
ty = g.pixelInset.y * multiplier;
height = g.pixelInset.height * multiplier;
g.pixelInset = new Rect(tx, ty,
width,
height);
Basically it just takes the original resolution (baseScreenHeight) which is set as a constant equal to whatever you set as the screen height for testing (such as 480 in a 320x480 screen). Then it does maths and changes the PixelInset of the GUITexture to the new screen resolution. Yay.
There's also a whole bunch of other stuff to consider, but I won't go into that - read this article. Especially the bit about density independence.
No comments:
Post a Comment