UnitySerializedReferenceUI/Editor/Attributes/SerializeReferenceMenuAttributeDrawer.cs

29 lines
1.0 KiB
C#
Raw Normal View History

#if UNITY_EDITOR
2022-12-28 14:03:46 +01:00
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
2022-12-28 14:06:42 +01:00
namespace Textus.SerializeReferenceUI.Editor
{
2022-12-28 14:06:42 +01:00
[CustomPropertyDrawer(typeof(SerializeReferenceMenuAttribute))]
public class SerializeReferenceMenuAttributeDrawer : PropertyDrawer
{
2022-12-28 14:06:42 +01:00
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property, true);
}
2022-12-28 14:06:42 +01:00
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
IEnumerable<Func<Type, bool>> typeRestrictions = SerializedReferenceUIDefaultTypeRestrictions.GetAllBuiltInTypeRestrictions(fieldInfo);
property.ShowContextMenuForManagedReferenceOnMouseMiddleButton(position, typeRestrictions);
2022-12-28 14:03:46 +01:00
2022-12-28 14:06:42 +01:00
EditorGUI.PropertyField(position, property, true);
EditorGUI.EndProperty();
}
}
}
2022-12-28 14:03:46 +01:00
#endif