Fixed issue, where changing DPI scaling on monitor would detach visual elements from toolbar and not reattach/rebuild
This commit is contained in:
parent
a9576ce008
commit
708b99f763
4 changed files with 26 additions and 6 deletions
|
|
@ -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<DetachFromPanelEvent>(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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue