From 2b5850183e21e9c678c8c89521304d9bf6e9c53b Mon Sep 17 00:00:00 2001 From: Whyser Date: Fri, 30 Apr 2021 16:41:33 +0200 Subject: [PATCH] will now show context menu below button (similar to how dropdown works) --- .../SerializeReferenceGenericSelectionMenu.cs | 20 ++++++++++++++++--- .../SerializeReferenceInspectorButton.cs | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Assets/Textus/SerializeReferenceUI/Core/SerializeReferenceGenericSelectionMenu.cs b/Assets/Textus/SerializeReferenceUI/Core/SerializeReferenceGenericSelectionMenu.cs index a7490a3..44d36d5 100644 --- a/Assets/Textus/SerializeReferenceUI/Core/SerializeReferenceGenericSelectionMenu.cs +++ b/Assets/Textus/SerializeReferenceUI/Core/SerializeReferenceGenericSelectionMenu.cs @@ -9,18 +9,32 @@ using UnityEngine; public static class SerializeReferenceGenericSelectionMenu { /// Purpose. - /// This is generic selection menu. + /// This is generic selection menu (will appear at position). /// Filtering. /// You can add substring filter here to filter by search string. /// As well ass type or interface restrictions. /// As well as any custom restriction that is based on input type. /// And it will be performed on each Appropriate type found by TypeCache. - public static void ShowContextMenuForManagedReference(this SerializedProperty property, IEnumerable> filters = null) + public static void ShowContextMenuForManagedReference(this SerializedProperty property, Rect position, IEnumerable> filters = null) { + var context = new GenericMenu(); + FillContextMenu(filters, context, property); + context.DropDown(position); + } + + /// Purpose. + /// This is generic selection menu (will appear at click position). + /// Filtering. + /// You can add substring filter here to filter by search string. + /// As well ass type or interface restrictions. + /// As well as any custom restriction that is based on input type. + /// And it will be performed on each Appropriate type found by TypeCache. + public static void ShowContextMenuForManagedReference(this SerializedProperty property, IEnumerable> filters = null) + { var context = new GenericMenu(); FillContextMenu(filters, context, property); context.ShowAsContext(); - } + } private static void FillContextMenu(IEnumerable> enumerableFilters, GenericMenu contextMenu, SerializedProperty property) { diff --git a/Assets/Textus/SerializeReferenceUI/DefaultUI/SerializeReferenceInspectorButton.cs b/Assets/Textus/SerializeReferenceUI/DefaultUI/SerializeReferenceInspectorButton.cs index 59b8879..d89b937 100644 --- a/Assets/Textus/SerializeReferenceUI/DefaultUI/SerializeReferenceInspectorButton.cs +++ b/Assets/Textus/SerializeReferenceUI/DefaultUI/SerializeReferenceInspectorButton.cs @@ -35,7 +35,7 @@ public static class SerializeReferenceInspectorButton var className = string.IsNullOrEmpty(names.ClassName) ? "Null (Assign)" : names.ClassName; var assemblyName = names.AssemblyName; if (GUI.Button(buttonPosition, new GUIContent(className, className + " ( "+ assemblyName +" )" ))) - property.ShowContextMenuForManagedReference(filters); + property.ShowContextMenuForManagedReference(buttonPosition, filters); GUI.backgroundColor = storedColor; EditorGUI.indentLevel = storedIndent;