From bf2b2f138386bfd54d609cab7a1ea784865bdbc0 Mon Sep 17 00:00:00 2001 From: Ejlersen Date: Wed, 10 Nov 2021 19:40:38 +0100 Subject: [PATCH] 1.0.0: Fixed issue, where toolbar elements could overlap with other toolbar elements in Unity 2020 and older --- Editor/Toolbar/ToolbarDrawer.cs | 15 ++++++++- Editor/Toolbar/Utilities/ToolbarUtility.cs | 37 ++++++++++++++++------ package.json | 2 +- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/Editor/Toolbar/ToolbarDrawer.cs b/Editor/Toolbar/ToolbarDrawer.cs index 0264003..3e25233 100644 --- a/Editor/Toolbar/ToolbarDrawer.cs +++ b/Editor/Toolbar/ToolbarDrawer.cs @@ -1,7 +1,10 @@ using Module.NavigationTool.Editor.Toolbar; using UnityEditor; using UnityEngine; + +#if UNITY_2021_1_OR_NEWER using UnityEngine.UIElements; +#endif namespace Module.NavigationTool.Editor { @@ -43,7 +46,7 @@ namespace Module.NavigationTool.Editor { const float HEIGHT = 22.0f; - for (var i = 0; i < DRAWERS.Length; i++) + for (int i = DRAWERS.Length - 1; i >= 0; i--) { AbstractToolbarDrawer drawer = DRAWERS[i]; var rect = new Rect(0.0f, 0.0f, drawer.CalculateWidth(), HEIGHT); @@ -86,11 +89,21 @@ namespace Module.NavigationTool.Editor { rect = new Rect(xLeft - width, Y, width, HEIGHT); xLeft -= width + SPACING; + + // Note: Magic number for closest right-most item left of play button (2020.3) + if (rect.xMin < 414.0f) + continue; } else { rect = new Rect(xRight, Y, width, HEIGHT); xRight += width + SPACING; + Debug.Log(rect.xMax); + + // Note: Magic number for closest left-most item right of play button (2020.3) + // If you don't have collab, which no sane person has + if (rect.xMax < 642.0f) + continue; } drawer.Setup(rect); diff --git a/Editor/Toolbar/Utilities/ToolbarUtility.cs b/Editor/Toolbar/Utilities/ToolbarUtility.cs index ad5a793..4897ee7 100644 --- a/Editor/Toolbar/Utilities/ToolbarUtility.cs +++ b/Editor/Toolbar/Utilities/ToolbarUtility.cs @@ -59,17 +59,18 @@ namespace Module.NavigationTool.Editor.Toolbar private static VisualElement CreateParent(VisualElement root, string query, bool isLeft) { VisualElement parent = root.Q(query); - - var result = new VisualElement - { - style = { - flexGrow = 1, - flexDirection = FlexDirection.Row - } - }; - + VisualElement result; + if (isLeft) { + result = new VisualElement + { + style = { + flexGrow = 1, + flexDirection = FlexDirection.Row + } + }; + result.Add(new VisualElement { style = { @@ -77,6 +78,24 @@ namespace Module.NavigationTool.Editor.Toolbar } }); } + else + { + result = new VisualElement + { + style = { + flexGrow = 1, + flexDirection = FlexDirection.RowReverse + } + }; + + result.Add(new VisualElement + { + style = + { + flexGrow = 1 + } + }); + } parent.Add(result); return result; diff --git a/package.json b/package.json index e888551..3357bce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.module.navigationtool", - "version": "0.8.3", + "version": "1.0.0", "displayName": "Module.NavigationTool", "description": "Support for navigation tools, like favorites, history and toolbars", "unity": "2019.2",