- Home /
Selection box - Borders scaling when selection box size grows
Using Unity 5.3.4
When drawing my selection box to the screen using :
GUI.DrawTexture(selectionRect, this.SelectionTexture);
The texture draws in the correct position, but the 1px border scales, which I don't want it do to. No matter the size of the selection box, I would like the border to stay at 1px.
I have adjusted the texture in the sprite editor to be of type Sprite (2D and UI)
, to be Single
and to have a border of L:1 B:1 R:1 T:1
I have seen a similar question asked here : http://answers.unity3d.com/questions/941880/9-sliced-legacy-gui.html but I'm unsure of the syntax that the accepted answer mentions.
Any clues what I might be doing wrong with GUI.DrawTexture()
to draw my texture as a sliced texture ? Or whether I need to use another method, and what that syntax might be ?
I had the same problem, after a day of trial and error i ended up creating a ui image where i got exactly what i wanted in 2 $$anonymous$$utes. I just turn it on and off and scale it as needed. $$anonymous$$ight be easier for you too.
The GUI.DrawTexture function is not meant to be used with Textures imported as 2D/Sprite assets AFAI$$anonymous$$. You have to either use OnGUI to draw a GUI Style that has the required border set up, or use the UI system.
Answer by Glurth · May 26, 2016 at 03:16 PM
While I don't know the exact details of how frames get scaled in the unity editor UI: I CAN tell you that this procedural texture (discovered via trial and error) DOES keep the lines 1 pixel in size, regardless of how large I scale it. It's basically 8x8 pixels, with a 1pix border of color(black here) on the edges:
Texture2D FrameTex()
{
int dim = 8;
Texture2D texture = new Texture2D(dim, dim, TextureFormat.ARGB32, false);
texture.alphaIsTransparency = true;
for (int i = 0; i < dim; i++)
for (int j = 0; j < dim; j++)
{
if (i == 0 || j == 0 || i == dim - 1 || j == dim - 1)
texture.SetPixel(i, j, new Color(0, 0, 0, 1));
else
texture.SetPixel(i, j, new Color(0, 0, 0, 0));
}
texture.Apply();
return texture;
}
Your answer
Follow this Question
Related Questions
9-Sliced Legacy GUI 2 Answers
Slice background texture for OnGUI button 0 Answers
How to make a GUI Texture (image) transparent? 2 Answers
Inter Scene Loading Screen Animation 3 Answers
RTS rectangle selection system 3 Answers