6
votes

I wanted my UI to not resize when user is still resizing the game (holding click in the window border) and only when the user has released the mouse the resize event will trigger.

I have tried to achieve it on Unity but so far I only able to detect windows size change, which my script checked every 0.5 second and if detected change it will resize the UI. But of course resizing everything caused a heavy lag, so resizing every 0.5 second is not a good option but resizing every 1 second is not a good idea either because 1 second is considered too long.

The question might be too broad but I have specified the problem as small as possible, how do I detect if user is still resizing the window? And how do I detect if user has stopped resizing the window (stop holding click at window border)?

1
i think its a rather well-formed concrete question - adding the code that you already tried to the answer would help a bit tho.sommmen
i don't think it is necessary , because it wouldn't help to answer the question . After all there's so many way to replicate what my code do without using the same code that my code uses .i'm ashamed with what i asked
Might be a bit of a hacky fix but would just waiting for a mouseClick-up event work?Jay
@sommmen - code is irrelevant, the problem is perfectly described.Fattie
Check this callback: OnRectTransformDimensionsChangeshingo

1 Answers

0
votes

I have some good news - sort of.

When the user resizes the window on Mac or PC,

Unity will AUTOMATICALLY re-layout everything.

BUT in fact ONLY when the user is "finished" resizing the Mac/PC window.

I believe that is what the OP is asking for - so the good news, what the OP is asking for is quite automatic.

However. A huge problem in Unity is Unity does not smoothly resize elements as the user is dragging the mouse to expand the Mac/PC window.

I have never found a solution to that problem. (A poor solution often mentioned is to check the size of the window every frame; that seems to be about the only approach.)

Again interestingly, what the OP mentions

" ..and if window has stopped resizing .."

is automatically done in Unity; in fact do nothing to achieve that.