You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 24, 2019. It is now read-only.
UIElementDocker remembers current window size and mouse offset from window position
UIElementDocker resizes window to docking size and adjusts position to the side
User clicks the window to undock
UIElementDocker restores the original window size and moves the window so that it has the original offset from the mouse
This is pretty good, but it's a little jarring since the window jumps to a different position relative to where on the window you clicked to undock it. A better undocking process looks like this:
User clicks the window to undock
UIElementDocker calculates the mouse's normalized position within the rect of the Dock-sized window. That means any point/mouse-position within the window becomes a Vector2 between 0,0 and 1,1.
UIElementDocker restores the original window size
UIElementDocker moves the window under the mouse such that the mouse occupies the same normalized position as when the docked window was initially clicked.
Unity has the following function to find the mouse's current local position within a given rectTransform:
RectTransformUtility.ScreenPointToLocalPointInRectangle(windowRectTransform, Input.mousePosition, GetComponentInParent<Canvas>().worldCamera, out mouseLocalPosition);
Unity also has the following to let us normalize that localPosition within the rectTransform:
So that gets us the normalized position on the initial click to undock, when the window is still dock-sized. After resizing, how do we move the window under the mouse, so the mouse occupies the same normalized position as before?
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Current docking process:
User drags window to side
UIElementDocker
remembers current window size and mouse offset from window positionUIElementDocker
resizes window to docking size and adjusts position to the sideUser clicks the window to undock
UIElementDocker
restores the original window size and moves the window so that it has the original offset from the mouseThis is pretty good, but it's a little jarring since the window jumps to a different position relative to where on the window you clicked to undock it. A better undocking process looks like this:
UIElementDocker
calculates the mouse's normalized position within the rect of the Dock-sized window. That means any point/mouse-position within the window becomes a Vector2 between0,0
and1,1
.UIElementDocker
restores the original window sizeUIElementDocker
moves the window under the mouse such that the mouse occupies the same normalized position as when the docked window was initially clicked.Unity has the following function to find the mouse's current local position within a given rectTransform:
Unity also has the following to let us normalize that localPosition within the rectTransform:
So that gets us the normalized position on the initial click to undock, when the window is still dock-sized. After resizing, how do we move the window under the mouse, so the mouse occupies the same normalized position as before?
The text was updated successfully, but these errors were encountered: