@@ -15,8 +15,16 @@ public static class ToolbarCallback
1515 {
1616 static Type m_toolbarType = typeof ( Editor ) . Assembly . GetType ( "UnityEditor.Toolbar" ) ;
1717 static Type m_guiViewType = typeof ( Editor ) . Assembly . GetType ( "UnityEditor.GUIView" ) ;
18+ #if UNITY_2020_1_OR_NEWER
19+ static Type m_iWindowBackendType = typeof ( Editor ) . Assembly . GetType ( "UnityEditor.IWindowBackend" ) ;
20+ static PropertyInfo m_windowBackend = m_guiViewType . GetProperty ( "windowBackend" ,
21+ BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) ;
22+ static PropertyInfo m_viewVisualTree = m_iWindowBackendType . GetProperty ( "visualTree" ,
23+ BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) ;
24+ #else
1825 static PropertyInfo m_viewVisualTree = m_guiViewType . GetProperty ( "visualTree" ,
1926 BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) ;
27+ #endif
2028 static FieldInfo m_imguiContainerOnGui = typeof ( IMGUIContainer ) . GetField ( "m_OnGUIHandler" ,
2129 BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance ) ;
2230 static ScriptableObject m_currentToolbar ;
@@ -42,8 +50,15 @@ static void OnUpdate()
4250 m_currentToolbar = toolbars . Length > 0 ? ( ScriptableObject ) toolbars [ 0 ] : null ;
4351 if ( m_currentToolbar != null )
4452 {
53+ #if UNITY_2020_1_OR_NEWER
54+ var windowBackend = m_windowBackend . GetValue ( m_currentToolbar ) ;
55+
56+ // Get it's visual tree
57+ var visualTree = ( VisualElement ) m_viewVisualTree . GetValue ( windowBackend , null ) ;
58+ #else
4559 // Get it's visual tree
4660 var visualTree = ( VisualElement ) m_viewVisualTree . GetValue ( m_currentToolbar , null ) ;
61+ #endif
4762
4863 // Get first child which 'happens' to be toolbar IMGUIContainer
4964 var container = ( IMGUIContainer ) visualTree [ 0 ] ;
0 commit comments