UnitySerializedReferenceUI/Assets/TextusGames/Enhancements/SerializeReferenceUI/Drawing/SerializeReferenceButton/SerializeReferenceButtonAttributeDrawer.cs
TextusGames 0581978db8 FIrst Real Commit
Code refactor and migration to github.
2020-05-16 16:17:04 +03:00

31 lines
1.0 KiB
C#

#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(SerializeReferenceButtonAttribute))]
public class SerializeReferenceButtonAttributeDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property, true);
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
var labelPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
EditorGUI.LabelField(labelPosition, label);
var typeRestrictions = SerializedReferenceUIBuiltInTypeRestrictions.GetAllBuiltInTypeRestrictions(fieldInfo);
property.DrawSelectionButtonForManagedReference(position, typeRestrictions);
EditorGUI.PropertyField(position, property, GUIContent.none, true);
EditorGUI.EndProperty();
}
}
#endif