SubclassSelectorDrawer support now custom property drawer
This commit is contained in:
parent
92c16eda3b
commit
b3b65ee8e5
@ -6,7 +6,8 @@ using UnityEngine;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEditor.IMGUI.Controls;
|
using UnityEditor.IMGUI.Controls;
|
||||||
|
|
||||||
namespace MackySoft.SerializeReferenceExtensions.Editor {
|
namespace MackySoft.SerializeReferenceExtensions.Editor
|
||||||
|
{
|
||||||
|
|
||||||
[CustomPropertyDrawer(typeof(SubclassSelectorAttribute))]
|
[CustomPropertyDrawer(typeof(SubclassSelectorAttribute))]
|
||||||
public class SubclassSelectorDrawer : PropertyDrawer {
|
public class SubclassSelectorDrawer : PropertyDrawer {
|
||||||
@ -46,8 +47,31 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
popup.TypePopup.Show(popupPosition);
|
popup.TypePopup.Show(popupPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the managed reference property.
|
// Check if a custom property drawer exists for this type.
|
||||||
|
PropertyDrawer customDrawer = GetCustomPropertyDrawer(property);
|
||||||
|
if (customDrawer != null)
|
||||||
|
{
|
||||||
|
// Draw the property with custom property drawer.
|
||||||
|
Rect foldoutRect = new Rect(position);
|
||||||
|
foldoutRect.height = EditorGUIUtility.singleLineHeight;
|
||||||
|
property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, label, true);
|
||||||
|
|
||||||
|
if (property.isExpanded)
|
||||||
|
{
|
||||||
|
using (new EditorGUI.IndentLevelScope(1))
|
||||||
|
{
|
||||||
|
Rect indentedRect = EditorGUI.IndentedRect(position);
|
||||||
|
float foldoutDifference = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
indentedRect.height -= foldoutDifference;
|
||||||
|
indentedRect.y += foldoutDifference;
|
||||||
|
customDrawer.OnGUI(indentedRect, property, label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
EditorGUI.PropertyField(position, property, label, true);
|
EditorGUI.PropertyField(position, property, label, true);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
EditorGUI.LabelField(position,label,k_IsNotManagedReferenceLabel);
|
EditorGUI.LabelField(position,label,k_IsNotManagedReferenceLabel);
|
||||||
}
|
}
|
||||||
@ -55,6 +79,16 @@ namespace MackySoft.SerializeReferenceExtensions.Editor {
|
|||||||
EditorGUI.EndProperty();
|
EditorGUI.EndProperty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PropertyDrawer GetCustomPropertyDrawer (SerializedProperty property)
|
||||||
|
{
|
||||||
|
Type propertyType = ManagedReferenceUtility.GetType(property.managedReferenceFullTypename);
|
||||||
|
if (propertyType != null && PropertyDrawerCache.TryGetPropertyDrawer(propertyType, out PropertyDrawer drawer))
|
||||||
|
{
|
||||||
|
return drawer;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
TypePopupCache GetTypePopup (SerializedProperty property) {
|
TypePopupCache GetTypePopup (SerializedProperty property) {
|
||||||
// Cache this string. This property internally call Assembly.GetName, which result in a large allocation.
|
// Cache this string. This property internally call Assembly.GetName, which result in a large allocation.
|
||||||
string managedReferenceFieldTypename = property.managedReferenceFieldTypename;
|
string managedReferenceFieldTypename = property.managedReferenceFieldTypename;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user