2022-12-28 17:05:22 +01:00
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
2022-12-28 14:03:46 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-05-16 15:17:04 +02:00
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2022-12-28 14:06:42 +01:00
|
|
|
|
namespace Textus.SerializeReferenceUI.Editor
|
2020-05-16 15:17:04 +02:00
|
|
|
|
{
|
2022-12-28 14:06:42 +01:00
|
|
|
|
[CustomPropertyDrawer(typeof(SerializeReferenceButtonAttribute))]
|
|
|
|
|
public class SerializeReferenceButtonAttributeDrawer : PropertyDrawer
|
2020-05-16 15:17:04 +02:00
|
|
|
|
{
|
2022-12-28 14:06:42 +01:00
|
|
|
|
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
|
|
|
|
{
|
|
|
|
|
return EditorGUI.GetPropertyHeight(property, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
|
|
|
{
|
|
|
|
|
Rect labelPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
|
|
|
|
|
EditorGUI.LabelField(labelPosition, label);
|
2020-05-16 15:17:04 +02:00
|
|
|
|
|
2022-12-28 14:06:42 +01:00
|
|
|
|
IEnumerable<Func<Type, bool>> typeRestrictions = SerializedReferenceUIDefaultTypeRestrictions.GetAllBuiltInTypeRestrictions(fieldInfo);
|
|
|
|
|
property.DrawSelectionButtonForManagedReference(position, typeRestrictions);
|
2022-12-28 14:03:46 +01:00
|
|
|
|
|
2022-12-28 14:06:42 +01:00
|
|
|
|
EditorGUI.PropertyField(position, property, GUIContent.none, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-16 15:17:04 +02:00
|
|
|
|
}
|
|
|
|
|
#endif
|