I’ve been experimenting a bit with GUI.Label() in Unity 2.6 to render a background image with a border and text on top. The documentation says that the border values affect the number of pixels in the background image that won’t be scaled, but what I found in practice is that it will scale the background image to fit the Rect size first, then it will apply the border settings.
So if I had a 32x32 texture where I didn’t want the outer 4 pixels scaled, and I defined a GUIStyle named “customStyle” that contained this texture as the background image and all the border settings set to 4, it would look correct with this call:
Okay, so the video quality is complete crap, but here’s a video I made showing that the background image scaling does work, and does respect the Border properties (Note that the background, while blurry, does scale) : http://www.youtube.com/watch?v=RNG4DIuxRqY
Having said that, I don’t know whether this behavior is different for Labels than for other elements, but surely there is a way to make it work.
No, that’s just an in-house tool we created to add watch variables and view and edit data while the game is running. It’s nice, but not Unity 3.0 nice
I would suggest creating either a custom GUIStyle or trying the Box style to see if the behavior is as expected there. If that doesn’t point to an answer, I’ll see if I can duplicate the issue.
I haven’t completely verified it yet, but I think I know when I get the problem. It is when the Rect width and height are smaller than the image width and height. So my original example wasn’t correct, and I should have said when you have this Rect:
OH! I ran into that before as well, and had completely forgotten about it. When I tried making a GUI skin for the first time, I ran into issues like that, and just started making the images bigger by default.
I never did any significant testing to find out the precise conditions that caused it, but I’d be willing to bet that you are on the right track.
I was able to confirm that border doesn’t work correctly when the Rect size is smaller than the image size. I exposed the Rect size as public variables in script and was able to see the problems start as soon as the Rect size became smaller than the image. It isn’t too bad in the beginning, but it will start to look like overlapping images if it becomes too small.
I guess the workaround is to just make different sized images, but it would be nice if Unity could handle it.