- Home /
Increase height of panel w/ gridlayout when new objects added
Hi,
Have recently started using the new gui system, but have become a stuck with increasing the vertical size of a panel with a gridlayout, as new objects are added to it. This is for an inventory system. Objects already in the current inventory are added to the panel with code & prefabs, and objects from other inventories can be dragged and dropped.
The prefabs are set to 250 x 125, and the grid to the same. I've include a scene and game screen grab. If anyone can give me a nudge in the right direction, I'd be very grateful.
Thank you. The parent with scrollrect and mask was already in place. Was missing the layout element, and it's much closer to what is needed now. If you would like to convert your comment to an answer, we can close this one off.
One more thing, if you happen to know off hand. I'd like to keep the display area panel with the gridlayout at the full size of its parent by default, and increase its height only when the number of rows exceeds the number which can be displayed without scrolling.
Any ideas?
Answer by Mmmpies · Feb 17, 2015 at 02:48 PM
Not totally clear what you want but I'd guess you need a parent panel for your inventory panel with a ScrollRect Component on it and a Mask.
Add a Content Size Filter to the inventory panel and set the prefabs to have a Layout Element with a minimum height/width set.
The panel should expand to fit items and the scroll rect will allow it to scroll.
You probably want to restrict movement to just vertical but that's up to you.
EDIT
Sorry, working on a very small screen so not always easy to see. I don't currently have access to Unity, hence the phone being used but...
I bet if you put a layout element on the panel itself you could set its min size with that.
You should be able to do this via code if the aspect ration/resolution is likely to change. Just find/add the Layout Element when the menu opens and set the minimum to be the size of the parents x/y.
Can't test it but it works alright in my head!