0.6.3: Fixed issue, where toolbar items didn't accept mouse input in 2021 or newer versions
This commit is contained in:
parent
17c55cd03c
commit
99c83ea6d3
9 changed files with 186 additions and 73 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using Game.NavigationTool.Editor.Toolbar;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Game.NavigationTool.Editor
|
||||
{
|
||||
|
|
@ -8,9 +9,8 @@ namespace Game.NavigationTool.Editor
|
|||
internal static class ToolbarDrawer
|
||||
{
|
||||
private static bool IS_INITIALIZED;
|
||||
private static IToolbarDrawer[] DRAWERS;
|
||||
private static Styles styles;
|
||||
|
||||
private static AbstractToolbarDrawer[] DRAWERS;
|
||||
|
||||
static ToolbarDrawer()
|
||||
{
|
||||
EditorApplication.update -= OnEditorUpdate;
|
||||
|
|
@ -21,9 +21,14 @@ namespace Game.NavigationTool.Editor
|
|||
{
|
||||
if (!IS_INITIALIZED)
|
||||
{
|
||||
styles = new Styles();
|
||||
DRAWERS = ToolbarUtility.GetAllDrawers();
|
||||
|
||||
#if UNITY_2021_1_OR_NEWER
|
||||
ToolbarUtility.OnUpdate(OnCreateElements);
|
||||
#else
|
||||
ToolbarUtility.AddGuiListener(OnGUI);
|
||||
#endif
|
||||
|
||||
IS_INITIALIZED = true;
|
||||
}
|
||||
|
||||
|
|
@ -33,6 +38,27 @@ namespace Game.NavigationTool.Editor
|
|||
}
|
||||
}
|
||||
|
||||
#if UNITY_2021_1_OR_NEWER
|
||||
private static void OnCreateElements(VisualElement leftAlign, VisualElement rightAlign)
|
||||
{
|
||||
const float HEIGHT = 22.0f;
|
||||
|
||||
for (var i = 0; i < DRAWERS.Length; i++)
|
||||
{
|
||||
AbstractToolbarDrawer drawer = DRAWERS[i];
|
||||
var rect = new Rect(0.0f, 0.0f, drawer.CalculateWidth(), HEIGHT);
|
||||
drawer.Setup(rect);
|
||||
|
||||
var container = new IMGUIContainer(drawer.OnGUI);
|
||||
container.style.width = rect.width;
|
||||
|
||||
if (drawer.Placement == EToolbarPlacement.Left)
|
||||
leftAlign.Add(container);
|
||||
else
|
||||
rightAlign.Add(container);
|
||||
}
|
||||
}
|
||||
#else
|
||||
private static void OnGUI()
|
||||
{
|
||||
const float Y = 5.0f;
|
||||
|
|
@ -44,19 +70,16 @@ namespace Game.NavigationTool.Editor
|
|||
if (DRAWERS == null)
|
||||
return;
|
||||
|
||||
styles.Initialize(GUI.skin);
|
||||
float xLeft = EditorGUIUtility.currentViewWidth * 0.5f + PLAY_BUTTON_OFFSET - PLAY_BUTTON_EXTENT;
|
||||
float xRight = EditorGUIUtility.currentViewWidth * 0.5f + PLAY_BUTTON_OFFSET + PLAY_BUTTON_EXTENT;
|
||||
|
||||
for (var i = 0; i < DRAWERS.Length; i++)
|
||||
{
|
||||
IToolbarDrawer drawer = DRAWERS[i];
|
||||
|
||||
if (!drawer.Visible)
|
||||
continue;
|
||||
AbstractToolbarDrawer drawer = DRAWERS[i];
|
||||
|
||||
GUI.enabled = drawer.Enabled;
|
||||
float width = drawer.CalculateWidth();
|
||||
|
||||
Rect rect;
|
||||
|
||||
if (drawer.Placement == EToolbarPlacement.Left)
|
||||
|
|
@ -70,10 +93,12 @@ namespace Game.NavigationTool.Editor
|
|||
xRight += width + SPACING;
|
||||
}
|
||||
|
||||
drawer.Draw(rect, styles);
|
||||
drawer.Setup(rect);
|
||||
drawer.OnGUI();
|
||||
}
|
||||
|
||||
GUI.enabled = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue