diff --git a/Assets/ToolbarExtender/Scripts/Editor/ToolbarCallback.cs b/Assets/ToolbarExtender/Scripts/Editor/ToolbarCallback.cs index 66599c2..2dcbf2c 100644 --- a/Assets/ToolbarExtender/Scripts/Editor/ToolbarCallback.cs +++ b/Assets/ToolbarExtender/Scripts/Editor/ToolbarCallback.cs @@ -2,7 +2,12 @@ using UnityEngine; using UnityEditor; using System.Reflection; + +#if UNITY_2019_1_OR_NEWER +using UnityEngine.UIElements; +#else using UnityEngine.Experimental.UIElements; +#endif namespace UnityToolbarExtender { @@ -58,4 +63,4 @@ static void OnGUI() if (handler != null) handler(); } } -} \ No newline at end of file +} diff --git a/Assets/ToolbarExtender/Scripts/Editor/ToolbarExtender.cs b/Assets/ToolbarExtender/Scripts/Editor/ToolbarExtender.cs index bcffcb0..6184f2c 100644 --- a/Assets/ToolbarExtender/Scripts/Editor/ToolbarExtender.cs +++ b/Assets/ToolbarExtender/Scripts/Editor/ToolbarExtender.cs @@ -18,11 +18,18 @@ public static class ToolbarExtender static ToolbarExtender() { Type toolbarType = typeof(Editor).Assembly.GetType("UnityEditor.Toolbar"); - FieldInfo toolIcons = toolbarType.GetField("s_ShownToolIcons", + +#if UNITY_2019_1_OR_NEWER + string fieldName = "k_ToolCount"; +#else + string fieldName = "s_ShownToolIcons"; +#endif + + FieldInfo toolIcons = toolbarType.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); #if UNITY_2019_1_OR_NEWER - m_toolCount = 7; + m_toolCount = toolIcons != null ? ((int) toolIcons.GetValue(null)) : 7; #elif UNITY_2018_1_OR_NEWER m_toolCount = toolIcons != null ? ((Array) toolIcons.GetValue(null)).Length : 6; #else