Resizable GUI textures

Hello, all.

Unity’s default GUI controls use very small textures which can be resized without any distortion. An example of this is the default GUI.Box which uses a texture like this:

28057-box.png

But can be used to make background boxes of any size and dimension.

Can you please share any insight on how to make custom GUI textures with these properties using Unity’s GUI system?

I can make my own 12x12 pixel textures but they end up being very plain. Is it possible to use a bigger texture and have Unity identify the portion of the texture to be used as a border and the portion in the center to be repeated as needed (as it seems to do with the default texture)?

You need to make your own GUISkin. Assets->Create->GUI Skin. Each element type has a “Style” and you’re looking for the “border” property to control this behaviour. Essentially it defines how thick (in pixels) the border/s are, which tells the GUI system to not stretch the borders but do stretch what’s inside. This is known as 9-slice scaling.

To use your custom GUISkin, give your script a public/inspector variable of GUISkin type and drag the asset in in the inspector. To can enable it by setting GUI.skin = mySkin;.

This looks to serve as a pretty good introduction, if you get stuck on your own: http://forum.unity3d.com/threads/creating-custom-gui-skins-part-one.113055/

Relevant docs/manual: