- Home /
How do I get the GUI Icon to stretch?
Okay, searched everywhere and still haven't gotten a good answer. I want the cards to be the texture of the button, and despite the fact that the container is a long rectangle, I can't get the guicontent image to scale to anything that's not square. Works great for square icons, but I need these cards to be card shaped.
I've really searched everywhere. Any help?
post the code you are using to display these and if you are using a guiskin, the relevant details like fixed width/height/stretech/etc (screenshot be best)
I'm not familiar with GUIContent, but it seems fairly limited. Try playing with the GUITexture and GUITexture.pixelInset value ins$$anonymous$$d.
The code is a little convoluted, but I'm using a matrix to resize everything and a GUIskin with its own styles (with fixed height and width set to 0 currently, because they were a headache)
void OnGUI() {
GUI.skin = my_skin;
scale.x = (float)Screen.width/1980.0f;
scale.y = (float)Screen.height/1080.0f;
scale.z = 1;
var sv$$anonymous$$at = GUI.matrix;
GUI.matrix = $$anonymous$$atrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
if(Event.current.type == EventType.Layout && Event.current.clickCount == 0)
GUI.matrix = $$anonymous$$atrix4x4.identity;
if(display_inventory){
inv_window_rect = GUI.Window(INV_WINDOW_ID, inv_window_rect, InventoryWindow, "", "$$anonymous$$enu Background");
}
DisplayToolTip();
GUI.matrix = sv$$anonymous$$at;
}
public void InventoryWindow(int id){
GUI.skin = my_skin;
int counter = 0;
GUI.Box(new Rect(580,250,620,550), "", "Inventory Background");
for(int y = 0; y < inventory_rows; y++){
for(int x = 0; x < inventory_cols; x++){
if(counter < PlayerScript.Inventory.Count){
GUI.Button (new Rect(411 + (x * button_width + (x*1.5f)), 285 + (y * button_height + (y*5)), button_width, button_height), new GUIContent(PlayerScript.Inventory[counter].material.mainTexture /*PlayerScript.Inventory[counter].ToolTip(PlayerScript.Inventory[counter])*/));
} else {
counter++;
}
}
SetToolTip();
GUI.DragWindow();
}
I think that 'headache' has to be tackled again. You need a GUIStyle to tell your GUIContent how to render and using fixedHeight and fixedWidth to shape the image as you need it, or trying Stretch/true to see if GUI.Button does it automatically) looks to me, from the docs, as the way to do this,.
Answer by Kallen330 · Feb 08, 2014 at 06:20 PM
I was able to solve my problem, it seems. I had to redo the matrix a bit to get the gui elements to scale correctly, and redo the shape of the buttons somewhat to get the proper proportion. The GUI button fixed height will resize it, but it's always proportional, which is a pain, so the proportion has to be correct in the first place.