marijnz / unity-toolbar-extender

Extend the Unity Toolbar with your own Editor UI code.
MIT License
1.67k stars 168 forks source link

Dragging Editor between two different-DPI displays makes added buttons disappear #34

Open EveriNN opened 1 year ago

EveriNN commented 1 year ago

Hello!

Windows allows you to change the scaling settings for a display by right-clicking the desktop and selecting "Display settings." It's possible to set different displays to different scales; for example, one monitor could have 100% scale, and another could have 150% scale.

If the main Unity Editor window is dragged from one monitor to another, and if the two monitors have different scaling settings in Windows, any custom content added to the toolbar using unity-toolbar-extender will disappear. It will reappear if Unity enters or exits Play Mode, if the Editor layout is changed, or if script compilation occurs.

It appears that changing the main editor's DPI causes the toolbar to be visually reset (which wipes out custom UI), but does not delete the toolbar's ScriptableObject (which is what unity-toolbar-extender checks to trigger re-adding the custom UI:

https://github.com/marijnz/unity-toolbar-extender/blob/dbd76ed996483d219c39d240f785b1790aa039ed/Editor/ToolbarCallback.cs#L47-L48

I tried also re-adding the buttons in response to any change in Screen.dpi or EditorGUIUtility.pixelsPerPoint. This fixed the dragging issue if just one window was open, but it had a side effect: if the Editor had multiple windows open, and they were on different DPI windows, moving the mouse from one window to another would cause many duplicate copies of the custom UI to be added to the toolbar.