Compare commits

...

6 commits

12 changed files with 211 additions and 26 deletions

View file

@ -2,6 +2,30 @@
All notable changes to this project will be documented in this file.
## [1.11.4] - 2025-09-21
### Fixed
- Fixed issue, where changing DPI scaling on monitor would detach visual elements from toolbar and not reattach/rebuild
## [1.11.3] - 2025-05-11
### Changed
- Changed type lookup to use TypeCache, instead of iterating through all assemblies
## [1.11.2] - 2024-11-26
### Added
- Added "Include Build Scenes", when sorting scenes into sub-menu
## [1.11.1] - 2024-11-25
### Added
- Added context menu to time scale, so it is possible to reset slider to 1.0
## [1.11.0] - 2025-03-29
### Changed

View file

@ -23,7 +23,7 @@ namespace Module.NavigationTool.Editor.Toolbar
EditorApplication.update -= OnEditorUpdate;
EditorApplication.update += OnEditorUpdate;
}
private static void OnEditorUpdate()
{
if (!IS_INITIALIZED)
@ -47,8 +47,8 @@ namespace Module.NavigationTool.Editor.Toolbar
DRAWERS[i].Update();
}
}
#if UNITY_2021_1_OR_NEWER
#if UNITY_2021_1_OR_NEWER
private static void OnUpdateElements(VisualElement leftAlign, VisualElement rightAlign)
{
const float HEIGHT = 22.0f;

View file

@ -9,6 +9,7 @@ namespace Module.NavigationTool.Editor.Toolbar
public string name;
public ESceneGroupFilterType filterType;
public ESceneGroupBehaviourType behaviourType;
public bool includeBuildScenes;
public string optionalMainScenePath;
public string subMenuPath = "Submenu";
public List<string> filters = new();

View file

@ -44,7 +44,8 @@ namespace Module.NavigationTool.Editor.Toolbar
{
name = asset.name,
shortname = asset.shortname,
paths = { asset.path }
paths = { asset.path },
inBuildSettings = true
});
}
}
@ -120,7 +121,11 @@ namespace Module.NavigationTool.Editor.Toolbar
continue;
filteredScenes = FilterToUniques(filteredScenes);
filteredScenes = FilterAllExcept(filteredScenes, scenes);
if (sceneGroup.includeBuildScenes)
filteredScenes = FilterAllExceptWithBuildScenes(filteredScenes, scenes);
else
filteredScenes = FilterAllExcept(filteredScenes, scenes);
if (filteredScenes.Count != 0)
scenes.Add(new SceneElement{ includeAsSelectable = false });
@ -195,6 +200,38 @@ namespace Module.NavigationTool.Editor.Toolbar
return filtered;
}
private static List<WorkingSetScene> FilterAllExceptWithBuildScenes(List<WorkingSetScene> list, List<SceneElement> except, bool includeGroups = false)
{
var filtered = new List<WorkingSetScene>(list.Count);
for (var i = 0; i < list.Count; i++)
{
var contains = false;
for (var j = except.Count - 1; j >= 0; j--)
{
if (except[j].isGroup && !includeGroups)
continue;
if (!except[j].paths.Contains(list[i].path))
continue;
if (except[j].inBuildSettings)
{
except.RemoveAt(j);
break;
}
contains = true;
break;
}
if (!contains)
filtered.Add(list[i]);
}
return filtered;
}
private void FetchAllLabels()
{
labels = new GUIContent[scenes.Count];
@ -395,6 +432,7 @@ namespace Module.NavigationTool.Editor.Toolbar
public string shortname;
public bool includeAsSelectable = true;
public bool isGroup;
public bool inBuildSettings;
public readonly List<string> paths = new List<string>();
}

View file

@ -1,6 +1,7 @@
using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
using UTools = UnityEditor.Tools;
namespace Module.NavigationTool.Editor.Toolbar
{

View file

@ -28,6 +28,16 @@ namespace Module.NavigationTool.Editor.Toolbar
EditorGUI.LabelField(r0, LABEL_TIME_SCALE, styles.centeredMiniLabel);
EditorGUI.LabelField(r2, LABEL_TIME_VALUE, styles.centeredMiniLabel);
if (Event.current.keyCode == KeyCode.Mouse1 && rect.Contains(Event.current.mousePosition))
{
GenericMenu menu = new GenericMenu();
menu.AddItem(new GUIContent("Reset"), false, () => Time.timeScale = 1f);
menu.ShowAsContext();
Event.current.Use();
}
float temp = GUI.HorizontalSlider(r1, value, ToolbarTimeSettings.TimeScaleMinValue, ToolbarTimeSettings.TimeScaleMaxValue);
temp = Mathf.Clamp(temp, ToolbarTimeSettings.TimeScaleMinValue, ToolbarTimeSettings.TimeScaleMaxValue);

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
@ -51,8 +52,10 @@ namespace Module.NavigationTool.Editor.Toolbar
}
else if (group.behaviourType == ESceneGroupBehaviourType.SortInSubmenuAsGroup)
{
var rectOptional = new Rect(rect.x, rectType.yMax + 2f, rect.width, EditorGUIUtility.singleLineHeight);
var rectIncludeBuildScenes = new Rect(rect.x, rectType.yMax + 2f, rect.width, EditorGUIUtility.singleLineHeight);
var rectOptional = new Rect(rect.x, rectIncludeBuildScenes.yMax + 2f, rect.width, EditorGUIUtility.singleLineHeight);
rectLabels = new Rect(rect.x, rectOptional.yMax + 2f, rect.width, rect.height - (rectName.y - rectOptional.yMax) - 4f);
group.includeBuildScenes = EditorGUI.Toggle(rectIncludeBuildScenes, "Include Build Scenes", group.includeBuildScenes);
group.subMenuPath = EditorGUI.TextField(rectOptional, "Sub-menu Path", group.subMenuPath);
}
@ -85,10 +88,26 @@ namespace Module.NavigationTool.Editor.Toolbar
protected override float OnElementHeight(int index)
{
int labelCount = list[index].filters.Count;
float extra;
switch (list[index].behaviourType)
{
case ESceneGroupBehaviourType.LoadAsGroup:
extra = 98f;
break;
case ESceneGroupBehaviourType.SortAsGroup:
extra = 80f;
break;
case ESceneGroupBehaviourType.SortInSubmenuAsGroup:
extra = 120f;
break;
default:
throw new ArgumentOutOfRangeException();
}
return base.OnElementHeight(index) * 3f
+ Mathf.Max(0, labelCount - 1) * (EditorGUIUtility.singleLineHeight + 2f)
+ 104f;
+ extra;
}
}
}

View file

@ -1,8 +1,13 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Serialization;
#if UNITY_2021_3 || UNITY_2022_2 || UNITY_6000_0_OR_NEWER
using UnityEditor;
#else
using System.Reflection;
#endif
namespace Module.NavigationTool.Editor.Toolbar
{
internal static class ToolbarSettingsUtility
@ -13,6 +18,21 @@ namespace Module.NavigationTool.Editor.Toolbar
try
{
#if UNITY_2021_3 || UNITY_2022_2 || UNITY_6000_0_OR_NEWER
var types = TypeCache.GetTypesDerivedFrom<IToolbarSettings>();
for (var i = 0; i < types.Count; i++)
{
Type type = types[i];
if (type.IsInterface || type.IsAbstract)
continue;
var toolbar = (IToolbarSettings)FormatterServices.GetUninitializedObject(type);
toolbar.Initialize();
list.Add(toolbar);
}
#else
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
Type iType = typeof(IToolbarSettings);
@ -33,6 +53,7 @@ namespace Module.NavigationTool.Editor.Toolbar
list.Add(toolbar);
}
}
#endif
list.Sort((s0, s1) => string.Compare(s0.Title, s1.Title, StringComparison.Ordinal));
}
@ -50,6 +71,21 @@ namespace Module.NavigationTool.Editor.Toolbar
try
{
#if UNITY_2021_3 || UNITY_2022_2 || UNITY_6000_0_OR_NEWER
var types = TypeCache.GetTypesDerivedFrom<IToolbarProjectSettings>();
for (var i = 0; i < types.Count; i++)
{
Type type = types[i];
if (type.IsInterface || type.IsAbstract)
continue;
var toolbar = (IToolbarProjectSettings)FormatterServices.GetUninitializedObject(type);
toolbar.Initialize(settings);
list.Add(toolbar);
}
#else
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
Type iType = typeof(IToolbarProjectSettings);
@ -70,6 +106,7 @@ namespace Module.NavigationTool.Editor.Toolbar
list.Add(toolbar);
}
}
#endif
list.Sort((s0, s1) => string.Compare(s0.Title, s1.Title, StringComparison.Ordinal));
}

View file

@ -5,6 +5,10 @@ using System.Reflection;
using System.Runtime.Serialization;
using Object = UnityEngine.Object;
#if UNITY_2021_3 || UNITY_2022_2 || UNITY_6000_0_OR_NEWER
using UnityEditor;
#endif
#if UNITY_2019_1_OR_NEWER
using UnityEngine.UIElements;
#else
@ -17,25 +21,27 @@ namespace Module.NavigationTool.Editor.Toolbar
{
private static readonly Assembly ASSEMBLY = typeof(UnityEditor.Editor).Assembly;
#if UNITY_2021_1_OR_NEWER
#if UNITY_2021_1_OR_NEWER
private static ScriptableObject CURRENT_TOOLBAR;
private static VisualElement CURRENT_ROOT;
private static VisualElement CURRENT_PARENT_LEFT;
private static VisualElement CURRENT_PARENT_RIGHT;
private static int CURRENT_INSTANCE_ID = -1;
#endif
private static int CURRENT_INSTANCE_ID;
private static FieldInfo FIELD_INFO_ROOT;
#endif
#if UNITY_2021_1_OR_NEWER
#if UNITY_2021_1_OR_NEWER
public static void OnUpdate(Action<VisualElement, VisualElement> callback)
{
if (CURRENT_TOOLBAR == null)
CURRENT_TOOLBAR = GetToolbarObject();
if (CURRENT_TOOLBAR != null && CURRENT_PARENT_LEFT != null && CURRENT_TOOLBAR.GetInstanceID() != CURRENT_INSTANCE_ID)
if (CURRENT_TOOLBAR != null && CURRENT_TOOLBAR.GetInstanceID() != CURRENT_INSTANCE_ID)
{
CURRENT_PARENT_LEFT.RemoveFromHierarchy();
CURRENT_PARENT_LEFT?.RemoveFromHierarchy();
CURRENT_PARENT_LEFT = null;
CURRENT_PARENT_RIGHT.RemoveFromHierarchy();
CURRENT_PARENT_RIGHT?.RemoveFromHierarchy();
CURRENT_PARENT_RIGHT = null;
CURRENT_INSTANCE_ID = CURRENT_TOOLBAR.GetInstanceID();
@ -44,17 +50,27 @@ namespace Module.NavigationTool.Editor.Toolbar
if (CURRENT_TOOLBAR == null)
return;
if (CURRENT_PARENT_LEFT == null)
if (CURRENT_PARENT_LEFT == null || CURRENT_PARENT_RIGHT == null || CURRENT_ROOT == null)
{
CURRENT_INSTANCE_ID = CURRENT_TOOLBAR.GetInstanceID();
CURRENT_PARENT_LEFT?.RemoveFromHierarchy();
CURRENT_PARENT_LEFT = null;
CURRENT_PARENT_RIGHT?.RemoveFromHierarchy();
CURRENT_PARENT_RIGHT = null;
FieldInfo root = CURRENT_TOOLBAR.GetType().GetField("m_Root", BindingFlags.NonPublic | BindingFlags.Instance);
object rawRoot = root?.GetValue(CURRENT_TOOLBAR);
var mRoot = rawRoot as VisualElement;
CURRENT_PARENT_LEFT = CreateParent(mRoot, "ToolbarZoneLeftAlign", true);
CURRENT_PARENT_RIGHT = CreateParent(mRoot, "ToolbarZoneRightAlign", false);
if (FIELD_INFO_ROOT == null)
FIELD_INFO_ROOT = CURRENT_TOOLBAR.GetType().GetField("m_Root", BindingFlags.NonPublic | BindingFlags.Instance);
object rawRoot = FIELD_INFO_ROOT?.GetValue(CURRENT_TOOLBAR);
CURRENT_ROOT = rawRoot as VisualElement;
if (CURRENT_ROOT != null)
{
CURRENT_PARENT_LEFT = CreateParent(CURRENT_ROOT, "ToolbarZoneLeftAlign", true);
CURRENT_PARENT_RIGHT = CreateParent(CURRENT_ROOT, "ToolbarZoneRightAlign", false);
}
}
if (CURRENT_PARENT_LEFT != null)
@ -108,10 +124,14 @@ namespace Module.NavigationTool.Editor.Toolbar
});
}
#if UNITY_6000_0_OR_NEWER
result.RegisterCallbackOnce<DetachFromPanelEvent>(OnDetachedFromPanel);
#endif
parent.Add(result);
return result;
}
#else
#else
public static void AddGuiListener(Action action)
{
ScriptableObject so = GetToolbarObject();
@ -153,7 +173,7 @@ namespace Module.NavigationTool.Editor.Toolbar
handler += action;
fiImguiContainer.SetValue(container, handler);
}
#endif
#endif
private static ScriptableObject GetToolbarObject()
{
@ -168,6 +188,17 @@ namespace Module.NavigationTool.Editor.Toolbar
try
{
#if UNITY_2021_3 || UNITY_2022_2 || UNITY_6000_0_OR_NEWER
var types = TypeCache.GetTypesDerivedFrom<AbstractToolbarDrawer>();
for (var i = 0; i < types.Count; i++)
{
Type type = types[i];
if (!type.IsAbstract)
list.Add((AbstractToolbarDrawer)FormatterServices.GetUninitializedObject(type));
}
#else
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
Type iType = typeof(AbstractToolbarDrawer);
@ -184,6 +215,7 @@ namespace Module.NavigationTool.Editor.Toolbar
list.Add((AbstractToolbarDrawer)FormatterServices.GetUninitializedObject(type));
}
}
#endif
list.Sort((t0, t1) => t0.Priority.CompareTo(t1.Priority));
}
@ -194,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
}
}

9
LICENSE Normal file
View file

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2025 ejlersen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

7
LICENSE.meta Normal file
View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 81eaa9f1644b27547b1195ceb554d6b9
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,6 +1,6 @@
{
"name": "com.module.navigationtool",
"version": "1.11.0",
"version": "1.11.4",
"displayName": "Module.NavigationTool",
"description": "Support for navigation tools, like favorites, history and toolbars",
"unity": "2019.2",