From 708b99f763ad8f424e04dbad14fd4065ffdf04e0 Mon Sep 17 00:00:00 2001 From: Anders Ejlersen Date: Sun, 21 Sep 2025 14:26:04 +0200 Subject: [PATCH] Fixed issue, where changing DPI scaling on monitor would detach visual elements from toolbar and not reattach/rebuild --- CHANGELOG.md | 6 ++++++ Editor/Toolbar/ToolbarDrawer.cs | 6 +++--- Editor/Toolbar/Utilities/ToolbarUtility.cs | 18 ++++++++++++++++-- package.json | 2 +- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 203e88e..4acaaed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. +## [1.11.4] - 2025-09-21 + +### Fixed +- Fixed issue, where changing DPI scaling on monitor would detach visual elements from toolbar and not reattach/rebuild + + ## [1.11.3] - 2025-05-11 ### Changed diff --git a/Editor/Toolbar/ToolbarDrawer.cs b/Editor/Toolbar/ToolbarDrawer.cs index 0ac99e5..c68d3cb 100644 --- a/Editor/Toolbar/ToolbarDrawer.cs +++ b/Editor/Toolbar/ToolbarDrawer.cs @@ -23,7 +23,7 @@ namespace Module.NavigationTool.Editor.Toolbar EditorApplication.update -= OnEditorUpdate; EditorApplication.update += OnEditorUpdate; } - + private static void OnEditorUpdate() { if (!IS_INITIALIZED) @@ -47,8 +47,8 @@ namespace Module.NavigationTool.Editor.Toolbar DRAWERS[i].Update(); } } - - #if UNITY_2021_1_OR_NEWER + +#if UNITY_2021_1_OR_NEWER private static void OnUpdateElements(VisualElement leftAlign, VisualElement rightAlign) { const float HEIGHT = 22.0f; diff --git a/Editor/Toolbar/Utilities/ToolbarUtility.cs b/Editor/Toolbar/Utilities/ToolbarUtility.cs index d1daf1c..01bb660 100644 --- a/Editor/Toolbar/Utilities/ToolbarUtility.cs +++ b/Editor/Toolbar/Utilities/ToolbarUtility.cs @@ -27,6 +27,7 @@ namespace Module.NavigationTool.Editor.Toolbar private static VisualElement CURRENT_PARENT_LEFT; private static VisualElement CURRENT_PARENT_RIGHT; private static int CURRENT_INSTANCE_ID; + private static FieldInfo FIELD_INFO_ROOT; #endif #if UNITY_2021_1_OR_NEWER @@ -58,9 +59,11 @@ namespace Module.NavigationTool.Editor.Toolbar CURRENT_PARENT_RIGHT?.RemoveFromHierarchy(); CURRENT_PARENT_RIGHT = null; + + if (FIELD_INFO_ROOT == null) + FIELD_INFO_ROOT = CURRENT_TOOLBAR.GetType().GetField("m_Root", BindingFlags.NonPublic | BindingFlags.Instance); - FieldInfo root = CURRENT_TOOLBAR.GetType().GetField("m_Root", BindingFlags.NonPublic | BindingFlags.Instance); - object rawRoot = root?.GetValue(CURRENT_TOOLBAR); + object rawRoot = FIELD_INFO_ROOT?.GetValue(CURRENT_TOOLBAR); CURRENT_ROOT = rawRoot as VisualElement; if (CURRENT_ROOT != null) @@ -121,6 +124,10 @@ namespace Module.NavigationTool.Editor.Toolbar }); } +#if UNITY_6000_0_OR_NEWER + result.RegisterCallbackOnce(OnDetachedFromPanel); +#endif + parent.Add(result); return result; } @@ -219,5 +226,12 @@ namespace Module.NavigationTool.Editor.Toolbar return list.ToArray(); } + +#if UNITY_6000_0_OR_NEWER + private static void OnDetachedFromPanel(DetachFromPanelEvent evt) + { + CURRENT_INSTANCE_ID = -1; + } +#endif } } \ No newline at end of file diff --git a/package.json b/package.json index e76908a..49ba91c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.module.navigationtool", - "version": "1.11.3", + "version": "1.11.4", "displayName": "Module.NavigationTool", "description": "Support for navigation tools, like favorites, history and toolbars", "unity": "2019.2",