Compare commits

..

No commits in common. "master" and "1.10.2" have entirely different histories.

16 changed files with 91 additions and 333 deletions

View file

@ -2,54 +2,16 @@
All notable changes to this project will be documented in this file. 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
- Scene groups to contain three different types of behaviours for grouping:
- Load As Group: Groups all scenes into a single entry
- Sort As Group: Sorts all scenes into entries close to each other in the dropdown
- Sort In Submenu As Group: Sorts all scenes into entries in a submenu
### Removed
- Removed "Scene sorting by Asset label" groups
## [1.10.2] - 2024-11-25 ## [1.10.2] - 2024-11-25
### Fixed ### Fixed
- Fixed issue, where scene picker would not prompt about unsaved scene changes - Fixed issue, where scene picker would not prompt about unsaved scene changes
## [1.10.1] - 2024-11-25 ## [1.10.1] - 2024-11-25
### Fixed ### Fixed
- Fixed issue, where scene picker settings wouldn't save, if removing a group element - Fixed issue, where scene picker settings wouldn't save, if removing a group element
## [1.10.0] - 2024-11-17 ## [1.10.0] - 2024-11-17
### Added ### Added

View file

@ -4,7 +4,7 @@ using UnityEditor.Overlays;
namespace Module.NavigationTool.Editor.SceneViewToolbar namespace Module.NavigationTool.Editor.SceneViewToolbar
{ {
[Overlay(typeof(SceneView), "unity-custom-tool-handle-utility", "Custom/Tool Settings")] [Overlay(typeof(SceneView), "unity-custom-tool-handle-utility", "Custom/Tool Settings", true)]
internal sealed class EditorSceneViewToolHandleOverlay : ToolbarOverlay internal sealed class EditorSceneViewToolHandleOverlay : ToolbarOverlay
{ {
public EditorSceneViewToolHandleOverlay() public EditorSceneViewToolHandleOverlay()

View file

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

View file

@ -1,9 +0,0 @@
namespace Module.NavigationTool.Editor.Toolbar
{
public enum ESceneGroupBehaviourType
{
LoadAsGroup,
SortAsGroup,
SortInSubmenuAsGroup
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 71206076ab694b109f3391c4f28bc506
timeCreated: 1743238963

View file

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

View file

@ -24,6 +24,7 @@ namespace Module.NavigationTool.Editor.Toolbar
List<WorkingSetScene> assets = GetWorkingSet(); List<WorkingSetScene> assets = GetWorkingSet();
FetchAllScenesFromBuildSettings(assets); FetchAllScenesFromBuildSettings(assets);
FetchAllScenesFromLabels(assets, settings.labels);
FetchAllScenesFromSceneGroups(assets, settings.sceneGroups); FetchAllScenesFromSceneGroups(assets, settings.sceneGroups);
FetchAllRemainingScenes(assets); FetchAllRemainingScenes(assets);
@ -44,14 +45,36 @@ namespace Module.NavigationTool.Editor.Toolbar
{ {
name = asset.name, name = asset.name,
shortname = asset.shortname, shortname = asset.shortname,
paths = { asset.path }, paths = { asset.path }
inBuildSettings = true
}); });
} }
} }
private void FetchAllScenesFromLabels(List<WorkingSetScene> assets, List<string> labels)
{
List<WorkingSetScene> filteredScenes = GetAllWorkingSetScenesWithLabels(assets, labels);
filteredScenes = FilterToUniques(filteredScenes);
filteredScenes = FilterAllExcept(filteredScenes, scenes);
if (filteredScenes.Count != 0)
scenes.Add(new SceneElement{ includeAsSelectable = false });
for (var i = 0; i < filteredScenes.Count; i++)
{
scenes.Add(new SceneElement
{
name = filteredScenes[i].name,
shortname = filteredScenes[i].shortname,
paths = { filteredScenes[i].path }
});
}
}
private void FetchAllScenesFromSceneGroups(List<WorkingSetScene> assets, SceneGroupArray sceneGroups) private void FetchAllScenesFromSceneGroups(List<WorkingSetScene> assets, SceneGroupArray sceneGroups)
{ {
if (sceneGroups.Count != 0)
scenes.Add(new SceneElement{ includeAsSelectable = false });
for (var i = 0; i < sceneGroups.Count; i++) for (var i = 0; i < sceneGroups.Count; i++)
{ {
SceneGroup sceneGroup = sceneGroups[i]; SceneGroup sceneGroup = sceneGroups[i];
@ -72,77 +95,28 @@ namespace Module.NavigationTool.Editor.Toolbar
name = sceneGroup.name.Replace("/", "\\"); name = sceneGroup.name.Replace("/", "\\");
} }
if (sceneGroup.behaviourType == ESceneGroupBehaviourType.LoadAsGroup) if (!string.IsNullOrEmpty(sceneGroup.optionalMainScenePath))
SetWorkingSceneAsFirst(filteredScenes, sceneGroup.optionalMainScenePath);
filteredScenes = FilterToUniques(filteredScenes);
var scene = new SceneElement
{ {
if (sceneGroups.Count != 0) name = name,
scenes.Add(new SceneElement{ includeAsSelectable = false }); shortname = name,
isGroup = true
if (!string.IsNullOrEmpty(sceneGroup.optionalMainScenePath)) };
SetWorkingSceneAsFirst(filteredScenes, sceneGroup.optionalMainScenePath);
for (var j = 0; j < filteredScenes.Count; j++)
filteredScenes = FilterToUniques(filteredScenes);
var scene = new SceneElement
{
name = name,
shortname = name,
isGroup = true
};
for (var j = 0; j < filteredScenes.Count; j++)
{
scene.paths.Add(filteredScenes[j].path);
}
scene.name += $" ({scene.paths.Count})";
scenes.Add(scene);
}
else if (sceneGroup.behaviourType == ESceneGroupBehaviourType.SortAsGroup)
{ {
filteredScenes = FilterToUniques(filteredScenes); scene.paths.Add(filteredScenes[j].path);
filteredScenes = FilterAllExcept(filteredScenes, scenes);
if (filteredScenes.Count != 0)
scenes.Add(new SceneElement{ includeAsSelectable = false });
for (var j = 0; j < filteredScenes.Count; j++)
{
scenes.Add(new SceneElement
{
name = filteredScenes[j].name,
shortname = filteredScenes[j].shortname,
paths = { filteredScenes[j].path }
});
}
}
else if (sceneGroup.behaviourType == ESceneGroupBehaviourType.SortInSubmenuAsGroup)
{
if (string.IsNullOrEmpty(sceneGroup.subMenuPath))
continue;
filteredScenes = FilterToUniques(filteredScenes);
if (sceneGroup.includeBuildScenes)
filteredScenes = FilterAllExceptWithBuildScenes(filteredScenes, scenes);
else
filteredScenes = FilterAllExcept(filteredScenes, scenes);
if (filteredScenes.Count != 0)
scenes.Add(new SceneElement{ includeAsSelectable = false });
for (var j = 0; j < filteredScenes.Count; j++)
{
scenes.Add(new SceneElement
{
name = $"{sceneGroup.subMenuPath}/{filteredScenes[j].name}",
shortname = filteredScenes[j].shortname,
paths = { filteredScenes[j].path }
});
}
} }
scene.name += $" ({scene.paths.Count})";
scenes.Add(scene);
} }
} }
private void FetchAllRemainingScenes(List<WorkingSetScene> assets) private void FetchAllRemainingScenes(List<WorkingSetScene> assets)
{ {
List<WorkingSetScene> filteredScenes = FilterAllExcept(assets, scenes); List<WorkingSetScene> filteredScenes = FilterAllExcept(assets, scenes);
@ -200,38 +174,6 @@ namespace Module.NavigationTool.Editor.Toolbar
return filtered; 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() private void FetchAllLabels()
{ {
labels = new GUIContent[scenes.Count]; labels = new GUIContent[scenes.Count];
@ -432,7 +374,6 @@ namespace Module.NavigationTool.Editor.Toolbar
public string shortname; public string shortname;
public bool includeAsSelectable = true; public bool includeAsSelectable = true;
public bool isGroup; public bool isGroup;
public bool inBuildSettings;
public readonly List<string> paths = new List<string>(); public readonly List<string> paths = new List<string>();
} }

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
namespace Module.NavigationTool.Editor.Toolbar namespace Module.NavigationTool.Editor.Toolbar
{ {
@ -7,6 +8,7 @@ namespace Module.NavigationTool.Editor.Toolbar
public string Title => "Scene"; public string Title => "Scene";
public bool IsSettingsDirty { get; private set; } public bool IsSettingsDirty { get; private set; }
private StringReorderableListDrawer assetLabelList;
private SceneGroupReorderableListDrawer sceneGroupList; private SceneGroupReorderableListDrawer sceneGroupList;
private ToolbarProjectSettings projectSettings; private ToolbarProjectSettings projectSettings;
@ -17,14 +19,18 @@ namespace Module.NavigationTool.Editor.Toolbar
this.projectSettings = projectSettings; this.projectSettings = projectSettings;
settings = projectSettings.GetValueAs<Settings>(); settings = projectSettings.GetValueAs<Settings>();
assetLabelList = new StringReorderableListDrawer(settings.labels, "Scene sorting by Asset label");
assetLabelList.onChanged += ToolScenePicker.SetAsDirty;
sceneGroupList = new SceneGroupReorderableListDrawer(settings.sceneGroups.groups, "Scene groups"); sceneGroupList = new SceneGroupReorderableListDrawer(settings.sceneGroups.groups, "Scene groups");
sceneGroupList.onChanged += ToolScenePicker.SetAsDirty; sceneGroupList.onChanged += ToolScenePicker.SetAsDirty;
} }
public void Draw() public void Draw()
{ {
assetLabelList.DoLayoutList();
sceneGroupList.DoLayoutList(); sceneGroupList.DoLayoutList();
IsSettingsDirty = sceneGroupList.IsDirty; IsSettingsDirty = assetLabelList.IsDirty || sceneGroupList.IsDirty;
} }
public void SetSettingsValue() public void SetSettingsValue()
@ -35,6 +41,7 @@ namespace Module.NavigationTool.Editor.Toolbar
[Serializable] [Serializable]
public sealed class Settings public sealed class Settings
{ {
public List<string> labels = new();
public SceneGroupArray sceneGroups = new(); public SceneGroupArray sceneGroups = new();
} }
} }

View file

@ -28,16 +28,6 @@ namespace Module.NavigationTool.Editor.Toolbar
EditorGUI.LabelField(r0, LABEL_TIME_SCALE, styles.centeredMiniLabel); EditorGUI.LabelField(r0, LABEL_TIME_SCALE, styles.centeredMiniLabel);
EditorGUI.LabelField(r2, LABEL_TIME_VALUE, 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); float temp = GUI.HorizontalSlider(r1, value, ToolbarTimeSettings.TimeScaleMinValue, ToolbarTimeSettings.TimeScaleMaxValue);
temp = Mathf.Clamp(temp, ToolbarTimeSettings.TimeScaleMinValue, ToolbarTimeSettings.TimeScaleMaxValue); temp = Mathf.Clamp(temp, ToolbarTimeSettings.TimeScaleMinValue, ToolbarTimeSettings.TimeScaleMaxValue);

View file

@ -1,5 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
@ -25,41 +24,26 @@ namespace Module.NavigationTool.Editor.Toolbar
SceneGroup group = list[index]; SceneGroup group = list[index];
var rectName = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight); var rectName = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
var rectBehaviourType = new Rect(rect.x, rectName.yMax + 2f, rect.width, EditorGUIUtility.singleLineHeight); var rectType = new Rect(rect.x, rectName.yMax + 2f, rect.width, EditorGUIUtility.singleLineHeight);
var rectType = new Rect(rect.x, rectBehaviourType.yMax + 2f, rect.width, EditorGUIUtility.singleLineHeight); var rectOptional = new Rect(rect.x, rectType.yMax + 2f, rect.width - 80f, EditorGUIUtility.singleLineHeight);
var rectLabels = new Rect(rect.x, rectType.yMax + 2f, rect.width, rect.height - (rectName.y - rectType.yMax) - 4f); var rectOptionalBtn = new Rect(rectOptional.xMax, rectType.yMax + 2f, 80f, EditorGUIUtility.singleLineHeight);
var rectLabels = new Rect(rect.x, rectOptional.yMax + 2f, rect.width, rect.height - (rectName.y - rectOptional.yMax) - 4f);
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
group.name = EditorGUI.TextField(rectName, "Name", group.name); group.name = EditorGUI.TextField(rectName, "Name", group.name);
group.optionalMainScenePath = EditorGUI.TextField(rectOptional, "Optional Main Scene Path", group.optionalMainScenePath);
if (group.behaviourType == ESceneGroupBehaviourType.LoadAsGroup)
if (GUI.Button(rectOptionalBtn, "Find"))
{ {
var rectOptional = new Rect(rect.x, rectType.yMax + 2f, rect.width - 80f, EditorGUIUtility.singleLineHeight); string mainScenePath = EditorUtility.OpenFilePanel("Scene", "Assets", "unity");
var rectOptionalBtn = new Rect(rectOptional.xMax, rectType.yMax + 2f, 80f, EditorGUIUtility.singleLineHeight);
rectLabels = new Rect(rect.x, rectOptional.yMax + 2f, rect.width, rect.height - (rectName.y - rectOptional.yMax) - 4f);
group.optionalMainScenePath = EditorGUI.TextField(rectOptional, "Optional Main Scene Path", group.optionalMainScenePath);
if (GUI.Button(rectOptionalBtn, "Find")) if (!string.IsNullOrEmpty(mainScenePath))
{ {
string mainScenePath = EditorUtility.OpenFilePanel("Scene", "Assets", "unity"); mainScenePath = mainScenePath.Substring(Application.dataPath.Length - 6);
group.optionalMainScenePath = mainScenePath;
if (!string.IsNullOrEmpty(mainScenePath))
{
mainScenePath = mainScenePath.Substring(Application.dataPath.Length - 6);
group.optionalMainScenePath = mainScenePath;
}
} }
} }
else if (group.behaviourType == ESceneGroupBehaviourType.SortInSubmenuAsGroup)
{
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);
}
group.behaviourType = (ESceneGroupBehaviourType)EditorGUI.EnumPopup(rectBehaviourType, "Behaviour Type", group.behaviourType);
group.filterType = (ESceneGroupFilterType)EditorGUI.EnumPopup(rectType, "Filter Type", group.filterType); group.filterType = (ESceneGroupFilterType)EditorGUI.EnumPopup(rectType, "Filter Type", group.filterType);
elements[index].DoList(rectLabels); elements[index].DoList(rectLabels);
@ -88,26 +72,10 @@ namespace Module.NavigationTool.Editor.Toolbar
protected override float OnElementHeight(int index) protected override float OnElementHeight(int index)
{ {
int labelCount = list[index].filters.Count; 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 return base.OnElementHeight(index) * 3f
+ Mathf.Max(0, labelCount - 1) * (EditorGUIUtility.singleLineHeight + 2f) + Mathf.Max(0, labelCount - 1) * (EditorGUIUtility.singleLineHeight + 2f)
+ extra; + 78f;
} }
} }
} }

View file

@ -1,12 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.Serialization;
#if UNITY_2021_3 || UNITY_2022_2 || UNITY_6000_0_OR_NEWER
using UnityEditor;
#else
using System.Reflection; using System.Reflection;
#endif using System.Runtime.Serialization;
namespace Module.NavigationTool.Editor.Toolbar namespace Module.NavigationTool.Editor.Toolbar
{ {
@ -18,21 +13,6 @@ namespace Module.NavigationTool.Editor.Toolbar
try 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(); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
Type iType = typeof(IToolbarSettings); Type iType = typeof(IToolbarSettings);
@ -53,7 +33,6 @@ namespace Module.NavigationTool.Editor.Toolbar
list.Add(toolbar); list.Add(toolbar);
} }
} }
#endif
list.Sort((s0, s1) => string.Compare(s0.Title, s1.Title, StringComparison.Ordinal)); list.Sort((s0, s1) => string.Compare(s0.Title, s1.Title, StringComparison.Ordinal));
} }
@ -71,21 +50,6 @@ namespace Module.NavigationTool.Editor.Toolbar
try 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(); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
Type iType = typeof(IToolbarProjectSettings); Type iType = typeof(IToolbarProjectSettings);
@ -106,7 +70,6 @@ namespace Module.NavigationTool.Editor.Toolbar
list.Add(toolbar); list.Add(toolbar);
} }
} }
#endif
list.Sort((s0, s1) => string.Compare(s0.Title, s1.Title, StringComparison.Ordinal)); list.Sort((s0, s1) => string.Compare(s0.Title, s1.Title, StringComparison.Ordinal));
} }

View file

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

View file

@ -1,9 +0,0 @@
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.

View file

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

View file

@ -22,15 +22,12 @@ Toolbars to the left and right of the play-buttons. Anything can be added, as lo
Several tools are available from start: Several tools are available from start:
* Build: Select build target and build
* Player Prefs: Delete all PlayerPrefs data
* Scene: Load any scene in the project easily by using the dropdown
* Target Frame Rate Scale: Adjust target frame rate from [10;144] from a slider
* Time Scale: Adjust the time scale from [0;1] from a slider
* UI Canvas: Select and center the camera on any Canvases in the scene
* UI Layer: Toggle the UI layer on/off * UI Layer: Toggle the UI layer on/off
* Settings: Open project or preferences * UI Canvas: Select and center the camera on any Canvases in the scene
* Save: Project save * Scene: Load any scene in the project easily by using the dropdown
* Time Scale: Adjust the time scale from [0;1] from a slider
* Target Frame Rate Scale: Adjust target frame rate from [10;144] from a slider
* Player Prefs: Delete all PlayerPrefs data
### Customization ### Customization

View file

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