mirror of
https://github.com/maxartz15/UnitySerializedReferenceUI.git
synced 2024-11-24 00:25:35 +01:00
Merge pull request #6 from Whyser/master
Will now show context menu below button (similar to how dropdowns work)
This commit is contained in:
commit
3480807e75
@ -9,18 +9,32 @@ using UnityEngine;
|
|||||||
public static class SerializeReferenceGenericSelectionMenu
|
public static class SerializeReferenceGenericSelectionMenu
|
||||||
{
|
{
|
||||||
/// Purpose.
|
/// Purpose.
|
||||||
/// This is generic selection menu.
|
/// This is generic selection menu (will appear at position).
|
||||||
/// Filtering.
|
/// Filtering.
|
||||||
/// You can add substring filter here to filter by search string.
|
/// You can add substring filter here to filter by search string.
|
||||||
/// As well ass type or interface restrictions.
|
/// As well ass type or interface restrictions.
|
||||||
/// As well as any custom restriction that is based on input type.
|
/// As well as any custom restriction that is based on input type.
|
||||||
/// And it will be performed on each Appropriate type found by TypeCache.
|
/// And it will be performed on each Appropriate type found by TypeCache.
|
||||||
public static void ShowContextMenuForManagedReference(this SerializedProperty property, IEnumerable<Func<Type,bool>> filters = null)
|
public static void ShowContextMenuForManagedReference(this SerializedProperty property, Rect position, IEnumerable<Func<Type,bool>> 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<Func<Type, bool>> filters = null)
|
||||||
|
{
|
||||||
var context = new GenericMenu();
|
var context = new GenericMenu();
|
||||||
FillContextMenu(filters, context, property);
|
FillContextMenu(filters, context, property);
|
||||||
context.ShowAsContext();
|
context.ShowAsContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void FillContextMenu(IEnumerable<Func<Type, bool>> enumerableFilters, GenericMenu contextMenu, SerializedProperty property)
|
private static void FillContextMenu(IEnumerable<Func<Type, bool>> enumerableFilters, GenericMenu contextMenu, SerializedProperty property)
|
||||||
{
|
{
|
||||||
|
@ -35,7 +35,7 @@ public static class SerializeReferenceInspectorButton
|
|||||||
var className = string.IsNullOrEmpty(names.ClassName) ? "Null (Assign)" : names.ClassName;
|
var className = string.IsNullOrEmpty(names.ClassName) ? "Null (Assign)" : names.ClassName;
|
||||||
var assemblyName = names.AssemblyName;
|
var assemblyName = names.AssemblyName;
|
||||||
if (GUI.Button(buttonPosition, new GUIContent(className, className + " ( "+ assemblyName +" )" )))
|
if (GUI.Button(buttonPosition, new GUIContent(className, className + " ( "+ assemblyName +" )" )))
|
||||||
property.ShowContextMenuForManagedReference(filters);
|
property.ShowContextMenuForManagedReference(buttonPosition, filters);
|
||||||
|
|
||||||
GUI.backgroundColor = storedColor;
|
GUI.backgroundColor = storedColor;
|
||||||
EditorGUI.indentLevel = storedIndent;
|
EditorGUI.indentLevel = storedIndent;
|
||||||
|
Loading…
Reference in New Issue
Block a user