Forum rules - please read before posting.

uGUI Inventory Text Alignment

Hi,

I spent 2 hours now trying to find out why the text when hovering over an inventory item is so misaligned but cannot find anything. Please somebody help :-) The text is at the right position (centered) when hovering over a normal hotspot but not when hovering over an inventory item. 

It seems totally misalligned. What determines where the text is rendered? I also tried to find the code but couldn't. What class is responsible? I would have expected the boundary box of the item is taken (btnSlot2) and then centered in this one both horizontally and vertically.

Example on screenshot below: mouse is hovering over second item but text is appearing mostly over first one.

image

Comments

  • And the text being displayed is the unmodified Hotspot UI?  The UI will always correct it's position if it's RectTransform would otherwise become off-screen, so check that.  What happens with a 3rd or 4th item?
  • In screenshot 1 you see the hotspot UI and inspector in the editor. I made the rect very small to not have these repositioning issues. Inside normal hotspots it's working great,just not on the inventory. 

    Screenshot 2 shows what happens in the inventory. The label get's moved to the right with each item but not the same width as the item. Is it possible that there is some side effect since I shrunk the items from 13 to 8 but it is still calculating with 13 for some reason? The positioning could fit the 13 approximately.

    imageimage
  • The number of item slots shouldn't affect it.  If you move the cursor slightly sideways, does the Hotspot menu also shift?  What I'm trying to determine is whether or not the Hotspot UI has reached the edge of the screen, and is no longer able to move.  What does the Hotspot UI look like in the Scene view at this time?
  • edited June 2015
    I debugged quite a lot and think I found the reason. The method Menu.GetSlotCentre() returns incorrect values. 

    Digging deeper I find MenuElement.GetSlotRectRelative(). I think this is the real culprit. Is it really ready for uGui? To me it seems it is for the old AC UI but not for Unity UI prefabs. There are all kinds of calculations and assumptions in there that can never be correct (involving some slot spacing etc). How can AC know how I layed out my Unity UI inventory slots? They could be anywhere on the screen.

    I think the only way that makes sense is to simply take the boundary rect of the linked inventory button which should be a one-liner, isn't it? It will return the correct rect. No manual calculations should be necessary.
  • Say no more.  I will fix it.
  • Thanks for the quick fix! Works great!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.