Skip to content

Commit e16bcf7

Browse files
committed
fix: Made GenericObjectDrawer recognize that the current target is generic and show it correctly even if the passed type is not generic
1 parent 4f64f51 commit e16bcf7

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

Editor/Drawers/GenericObjectDrawer.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ public static void ObjectField(Rect rect, SerializedProperty property, GUIConten
4646
public static Object ObjectField(Rect rect, GUIContent label, Object currentTarget, Type objType,
4747
bool allowSceneObjects)
4848
{
49-
return objType.IsGenericType
50-
? EditorGUIHelper.GenericObjectField(rect, label, currentTarget, objType, allowSceneObjects)
51-
: EditorGUI.ObjectField(rect, label ?? GUIContent.none, currentTarget, objType, allowSceneObjects);
49+
if (objType.IsGenericType || IsTargetGeneric(currentTarget))
50+
return EditorGUIHelper.GenericObjectField(rect, label, currentTarget, objType, allowSceneObjects);
51+
52+
return EditorGUI.ObjectField(rect, label ?? GUIContent.none, currentTarget, objType, allowSceneObjects);
5253
}
5354

5455
/// <summary>
@@ -64,9 +65,25 @@ public static Object ObjectField(Rect rect, GUIContent label, Object currentTarg
6465
public static Object ObjectField(string label, Object currentTarget, Type objType,
6566
bool allowSceneObjects)
6667
{
67-
return objType.IsGenericType
68-
? EditorGUILayoutHelper.GenericObjectField(label, currentTarget, objType, allowSceneObjects)
69-
: EditorGUILayout.ObjectField(label, currentTarget, objType, allowSceneObjects);
68+
if (objType.IsGenericType || IsTargetGeneric(currentTarget))
69+
{
70+
return EditorGUILayoutHelper.GenericObjectField(label, currentTarget, objType, allowSceneObjects);
71+
}
72+
73+
return EditorGUILayout.ObjectField(label, currentTarget, objType, allowSceneObjects);
74+
}
75+
76+
private static bool IsTargetGeneric(Object target)
77+
{
78+
if (target == null)
79+
return false;
80+
81+
var targetBaseType = target.GetType().BaseType;
82+
83+
if (targetBaseType == null)
84+
return false;
85+
86+
return targetBaseType.IsGenericType;
7087
}
7188
}
7289
}

0 commit comments

Comments
 (0)