Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit 26faf5e

Browse files
Fixed developer descriptions not working in default inspectors
1 parent ea21a84 commit 26faf5e

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

Assets/SO Architecture/Editor/Drawers/DeveloperDescriptionDrawer.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,63 @@
66
[CustomPropertyDrawer(typeof(DeveloperDescription))]
77
public class DeveloperDescriptionDrawer : PropertyDrawer
88
{
9-
private SerializedProperty _property;
10-
9+
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
10+
{
11+
SerializedProperty stringValue = property.FindPropertyRelative("_value");
12+
13+
return Styles.TextAreaStyle.CalcSize(new GUIContent("Descriptions\n" + stringValue.stringValue)).y;
14+
}
1115
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
1216
{
13-
this._property = property;
14-
15-
DrawTitle();
16-
DrawTextArea();
17+
DrawTitle(ref position);
18+
DrawTextArea(ref position, property);
1719

1820
property.serializedObject.ApplyModifiedProperties();
1921
}
20-
private void DrawTitle()
22+
private void DrawTitle(ref Rect rect)
2123
{
22-
EditorGUILayout.LabelField(new GUIContent("Description", "Click below this field to add a description"));
24+
EditorGUI.LabelField(rect, new GUIContent("Description", "Click below this field to add a description"));
25+
26+
rect.y += EditorGUIUtility.singleLineHeight;
2327
}
24-
private void DrawTextArea()
28+
private void DrawTextArea(ref Rect rect, SerializedProperty property)
2529
{
26-
SerializedProperty stringValue = _property.FindPropertyRelative("_value");
30+
SerializedProperty stringValue = property.FindPropertyRelative("_value");
2731

2832
Vector2 fieldSize = Styles.TextAreaStyle.CalcSize(new GUIContent(stringValue.stringValue));
29-
Rect textAreaRect = GUILayoutUtility.GetRect(fieldSize.x, fieldSize.y);
30-
31-
32-
EditorGUI.indentLevel++;
33-
34-
stringValue.stringValue = EditorGUI.TextArea(textAreaRect, stringValue.stringValue, Styles.TextAreaStyle);
33+
rect.height = fieldSize.y;
3534

35+
EditorGUI.indentLevel++;
36+
stringValue.stringValue = EditorGUI.TextArea(rect, stringValue.stringValue, Styles.TextAreaStyle);
3637
EditorGUI.indentLevel--;
3738

38-
39-
HandleInput(textAreaRect);
39+
HandleInput(rect, property);
4040
}
41-
private void HandleInput(Rect textAreaRect)
41+
private void HandleInput(Rect textAreaRect, SerializedProperty property)
4242
{
4343
Event e = Event.current;
4444

4545
if(e.type == EventType.MouseDown)
4646
{
4747
if (!textAreaRect.Contains(e.mousePosition))
48-
RemoveFocus();
48+
RemoveFocus(property);
4949
}
5050
else if(e.type == EventType.KeyDown || e.type == EventType.KeyUp)
5151
{
5252
if (Event.current.keyCode == (KeyCode.Escape))
5353
{
54-
RemoveFocus();
54+
RemoveFocus(property);
5555
}
5656
}
5757
}
58-
private void RemoveFocus()
58+
private void RemoveFocus(SerializedProperty property)
5959
{
6060
GUI.FocusControl(null);
61-
Repaint();
61+
Repaint(property);
6262
}
63-
private void Repaint()
63+
private void Repaint(SerializedProperty property)
6464
{
65-
EditorUtility.SetDirty(_property.serializedObject.targetObject);
65+
EditorUtility.SetDirty(property.serializedObject.targetObject);
6666
}
6767
private static class Styles
6868
{

0 commit comments

Comments
 (0)