Skip to content

Commit

Permalink
Fixed arrays throwing exceptions when calling GetPropertyHeight
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielEverland committed May 7, 2019
1 parent 0dadf9a commit 6157053
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Assets/SO Architecture/Editor/Drawers/BaseReferenceDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
useConstant = property.FindPropertyRelative("_useConstant");
constantValue = property.FindPropertyRelative("_constantValue");
variable = property.FindPropertyRelative("_variable");

int oldIndent = ResetIndent();

Rect fieldRect = DrawLabel(position, property, label);
Expand Down Expand Up @@ -144,10 +144,11 @@ private Rect GetPopupButtonRect(Rect fieldrect)

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (SupportsMultiLine(property.FindPropertyRelative(CONSTANT_VALUE_PROPERTY_NAME)))
SerializedProperty constantValue = property.FindPropertyRelative(CONSTANT_VALUE_PROPERTY_NAME);
if (SupportsMultiLine(constantValue))
{
SerializedProperty useConstant = property.FindPropertyRelative(USE_CONSTANT_VALUE_PROPERTY_NAME);
var constantPropertyHeight = EditorGUI.GetPropertyHeight(property.FindPropertyRelative(CONSTANT_VALUE_PROPERTY_NAME));
var constantPropertyHeight = EditorGUI.GetPropertyHeight(constantValue);
return !useConstant.boolValue || constantPropertyHeight <= EditorGUIUtility.singleLineHeight
? EditorGUIUtility.singleLineHeight
: EditorGUIUtility.singleLineHeight * 2 + constantPropertyHeight;
Expand All @@ -160,7 +161,10 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent

public bool SupportsMultiLine(SerializedProperty property)
{
return SupportsMultiLine(GetReferenceGenericType(property));
Type baseReferenceType = GetReferenceType(property);
FieldInfo constantValueField = baseReferenceType.GetField(CONSTANT_VALUE_PROPERTY_NAME, BindingFlags.Instance | BindingFlags.NonPublic);

return SupportsMultiLine(constantValueField.FieldType);
}
public bool SupportsMultiLine(Type type)
{
Expand Down

0 comments on commit 6157053

Please sign in to comment.