|
6 | 6 | using UnityEditor;
|
7 | 7 | using UnityEditor.IMGUI.Controls;
|
8 | 8 |
|
9 |
| -namespace MackySoft.SerializeReferenceExtensions.Editor { |
| 9 | +namespace MackySoft.SerializeReferenceExtensions.Editor |
| 10 | +{ |
10 | 11 |
|
11 | 12 | [CustomPropertyDrawer(typeof(SubclassSelectorAttribute))]
|
12 | 13 | public class SubclassSelectorDrawer : PropertyDrawer {
|
@@ -46,15 +47,48 @@ public override void OnGUI (Rect position,SerializedProperty property,GUIContent
|
46 | 47 | popup.TypePopup.Show(popupPosition);
|
47 | 48 | }
|
48 | 49 |
|
49 |
| - // Draw the managed reference property. |
50 |
| - EditorGUI.PropertyField(position,property,label,true); |
| 50 | + // Check if a custom property drawer exists for this type. |
| 51 | + PropertyDrawer customDrawer = GetCustomPropertyDrawer(property); |
| 52 | + if (customDrawer != null) |
| 53 | + { |
| 54 | + // Draw the property with custom property drawer. |
| 55 | + Rect foldoutRect = new Rect(position); |
| 56 | + foldoutRect.height = EditorGUIUtility.singleLineHeight; |
| 57 | + property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, label, true); |
| 58 | + |
| 59 | + if (property.isExpanded) |
| 60 | + { |
| 61 | + using (new EditorGUI.IndentLevelScope(1)) |
| 62 | + { |
| 63 | + Rect indentedRect = EditorGUI.IndentedRect(position); |
| 64 | + float foldoutDifference = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; |
| 65 | + indentedRect.height -= foldoutDifference; |
| 66 | + indentedRect.y += foldoutDifference; |
| 67 | + customDrawer.OnGUI(indentedRect, property, label); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + else |
| 72 | + { |
| 73 | + EditorGUI.PropertyField(position, property, label, true); |
| 74 | + } |
51 | 75 | } else {
|
52 | 76 | EditorGUI.LabelField(position,label,k_IsNotManagedReferenceLabel);
|
53 | 77 | }
|
54 | 78 |
|
55 | 79 | EditorGUI.EndProperty();
|
56 | 80 | }
|
57 | 81 |
|
| 82 | + PropertyDrawer GetCustomPropertyDrawer (SerializedProperty property) |
| 83 | + { |
| 84 | + Type propertyType = ManagedReferenceUtility.GetType(property.managedReferenceFullTypename); |
| 85 | + if (propertyType != null && PropertyDrawerCache.TryGetPropertyDrawer(propertyType, out PropertyDrawer drawer)) |
| 86 | + { |
| 87 | + return drawer; |
| 88 | + } |
| 89 | + return null; |
| 90 | + } |
| 91 | + |
58 | 92 | TypePopupCache GetTypePopup (SerializedProperty property) {
|
59 | 93 | // Cache this string. This property internally call Assembly.GetName, which result in a large allocation.
|
60 | 94 | string managedReferenceFieldTypename = property.managedReferenceFieldTypename;
|
|
0 commit comments