2
« on: September 06, 2016, 08:54:04 AM »
I'm developing some dynamic gui using preparded templates ( a couple of empty widgets ( 1 to 4 ) anchored relatively to fullscreen rectangle per template ). What I do, is I parent other widgets to those prepared before, setting their relative anchors to [ 0.0, 1.0, 1.0, 0.0 ] to fill whole parent/template widget. I do it from code setting 'target' and 'relative' value. Unfortunately it doesnt work. It seems like everything is setuped right, inspector shows proper values, but the result is wrong. It looks like that the widgets that are nested the most in hierarchy are updated without parents being updated first or something.
For example: when w template widget is set to be in the in the right, top corner and size is setuped to be [50%, 50%] screen soze, and I set it's child to fill it ( target is set to template widget, left is set to left 0, right to right 0, top to top 0, bottom to bottom 0 ), it get size of [100%, 50%] screen, from the middle to the bottom ( so its in the wrong place and two times bigger then it should ) ).
Is there any known bug? Am I doing something wrong? What should I do to make it working properly? Should I call anything after setting targets and relative values? Update mode is set to OnUpdate.
EDIT1:
Oh. And doing the same from editor works fine. Unity shows THE SAME values, but the result is totaly different.
EDIT2:
When I pause the game, remove the anchor target, set it up again to the same value, the values seem to be recalculated ( I have to set all offsets back to 0 as desired ), and everything is in place. I tried to do kinda thesame from code - set anchor to null and the to desired one - but no luck.
EDIT3 - Found hacky walkaround!
I followed your UIRectEditor - since it gives proper results. I've found that when a target is definded UpdateHorizontalAnchor and UpdateVerticalAnchor methods are invoked, and relatives are being set to desired values. So I did thesame. I've copied those methods to non-editor class script and invoked them manually after setting new anchors, and set the relatives to [0, 1, 1, 0] ( as wanted, to fill in the parrent ). It works as desired.
It's clear to me that there is some bug. It should be fixed!