- Home /
Why is a tooltip ignoring a Rect and not another?
Hi, I didn't figure out how to write a good title, sorry.
I'm trying to make a grid of buttons to appear as an inventory. I'm totally new at Unity, please excuse my ignorance..
I'm rendering the inventory on the OnGUI event, I specify the position and size of the inventory area, and then I specify a portion of it to an area called tooltipArea. I want to hover a button and a tooltip that appears on the bottom part of the inventory (in the tooltipArea), with some characteristics of the item hovered.
What I did is that I assigned the tooltip to a button succesfully, but this tooltip won't appear if it's outside of the button area.
This is a screenshot of what I have:
And this is my code:
void OnGUI(){
GUI.skin = inventorySkin;
if(isMenuOpen){
//These boxes are for seeing what space are this areas actually occupying
GUI.Box(new Rect(inventoryAreaNormalized.x - inventoryBackPadding, inventoryAreaNormalized.y - inventoryBackPadding, inventoryAreaNormalized.width + inventoryBackPadding*2, inventoryAreaNormalized.height + inventoryBackPadding),"");
GUI.Box(new Rect(tooltipArea),"");
GUI.BeginGroup(inventoryAreaNormalized);
int count = 0;
//My intent of grid...
for(int renglon = 0; renglon < nrenglones; renglon++){
var top = renglon * baseItemArea.height;
for(int columna = 0; columna < colSize ; columna++){
var left = columna * baseItemArea.width;
var thisRect = new Rect(left, top, baseItemArea.width, baseItemArea.height);
if(Inventory.ItemBag.Count > count){
if(GUI.Button(new Rect(thisRect), new GUIContent(Inventory.ItemBag[count].Quantity.ToString(), Inventory.ItemBag[count].Icon, Inventory.ItemBag[count].Name))){
//Some actions
}
//THIS DOES NOT WORK
if (!string.IsNullOrEmpty(GUI.tooltip))
GUI.Box (new Rect(tooltipArea), GUI.tooltip);
count++;
}else if(renglon * colSize + columna + 1 <= Inventory.Capacity){
if(GUI.Button(new Rect(thisRect), "")){ }
}else{ items
GUI.Box(new Rect(thisRect),"");
}
}
}
GUI.EndGroup();
}
}
Ok, so please, any guidance is very welcome, I'm just playing around and I can't figure this out, I searched in the questions in this forum and I didn't got this particular question.
Again, to clarify, this line:
GUI.Box (new Rect(tooltipArea), GUI.tooltip);
only works like this
GUI.Box (new Rect(thisRect), GUI.tooltip);
placing the tooltip over the button (an undesired effect).
Edit:
So I changed
GUI.Box (
new Rect(thisRect.x+15,
thisRect.y+15,
thisRect.width,
thisRect.height), GUI.tooltip);
just to see if it had something to do with the button area, but no. This is the result:
Why is the tooltip ignoring the tooltipArea? What am I missing?
Answer by PaolaFalcon · Aug 12, 2013 at 10:20 PM
Can't believe my ignorance and inexperience.
Never ocurred to me that this bit was the thing I was not aware of. Sorry all.
GUI.BeginGroup(inventoryAreaNormalized);
Everything inside it is a 'child' of it, and I forgot.