Skip to content

Commit

Permalink
fix: property decorators produces visual artefacts
Browse files Browse the repository at this point in the history
  • Loading branch information
slavniyteo committed Aug 28, 2017
1 parent 7a804ea commit 3c84a20
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
20 changes: 19 additions & 1 deletion Assets/OneLine/Editor/Drawers/SimpleFieldDrawer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
Expand All @@ -9,9 +10,26 @@ internal class SimpleFieldDrawer : Drawer {

public override void Draw(Rect rect, SerializedProperty property) {
EditorGUI.BeginProperty(rect, GUIContent.none, property);
EditorGUI.PropertyField(rect, property, GUIContent.none);
DrawProperty(rect, property);
EditorGUI.EndProperty();
}

/*
* WORKAROUND
* Unity3d `feature`: EditorGUI.PropertyField draws field
* with all decorators (like Header, Space, etc) and this behaviour
* can not be ommited.
* see: http://answers.unity3d.com/questions/1394991/how-to-preserve-drawing-decoratordrawer-like-heade.html
* Headers and Separators (provided by one-line) produces artefacts.
* We solve this problem with reflection, but we call internal method
* and this may be dangerous: unity3d developers may change API =(
*/
private void DrawProperty(Rect rect, SerializedProperty property){
//EditorGUI.PropertyField(rect, property, GUIContent.none);
typeof(EditorGUI)
.GetMethod("DefaultPropertyField", BindingFlags.NonPublic | BindingFlags.Static)
.Invoke(null, new object[]{rect, property, GUIContent.none});
}

}
}
34 changes: 0 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,37 +357,3 @@ public class Example : ScriptableObject {
**Result:**

![Fixed Length Attribute Example](mdsrc/separator-attribute-example.png)

# Known issues

## Property decorators on nested fields

If nested field marked with some property decorator attribute (like `Space` or `Header`), decorator continues drawing and produces visual artefacts. I do not know how to prevent this behaviour. And community doesn't know too: [see my question without answers](http://answers.unity3d.com/questions/1394991/how-to-preserve-drawing-decoratordrawer-like-heade.html)

**Example:**

```csharp
using System;
using UnityEngine;
using OneLine;

[CreateAssetMenu]
public class Example : ScriptableObject {
[SerializeField, OneLine]
private ThreeFields threeFields;

[Serializable]
public class ThreeFields {
[SerializeField]
private string first;
[SerializeField, Header("Header is here")]
private string second;
[SerializeField]
private string third;
}
}
```

**Result:**

![One Line Attribute Example](mdsrc/issue-decorators-example.png)
Binary file removed mdsrc/issue-decorators-example.png
Binary file not shown.

0 comments on commit 3c84a20

Please sign in to comment.