public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { if (property.propertyType == SerializedPropertyType.ObjectReference && (property.objectReferenceValue as Sprite) != null) { PreviewSpriteAttribute previewSpriteAttribute = attribute as PreviewSpriteAttribute; return((previewSpriteAttribute.DisplayField ? EditorGUI.GetPropertyHeight(property, label, true) : 0) + previewSpriteAttribute.Heigth + 10); } return(EditorGUI.GetPropertyHeight(property, label, true)); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { PreviewSpriteAttribute previewSpriteAttribute = attribute as PreviewSpriteAttribute; //Draw the normal property field if (previewSpriteAttribute.DisplayField) { EditorGUI.PropertyField(position, property, label, true); position.y += EditorGUI.GetPropertyHeight(property, label, true) + 5; } if (property.propertyType == SerializedPropertyType.ObjectReference) { Sprite sprite = property.objectReferenceValue as Sprite; if (sprite != null) { position.height = previewSpriteAttribute.Heigth; //GUI.DrawTexture(position, sprite.texture, ScaleMode.ScaleToFit); DrawTexturePreview(position, sprite); } } }