|
6 | 6 | [CustomPropertyDrawer(typeof(DeveloperDescription))]
|
7 | 7 | public class DeveloperDescriptionDrawer : PropertyDrawer
|
8 | 8 | {
|
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 | + } |
11 | 15 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
12 | 16 | {
|
13 |
| - this._property = property; |
14 |
| - |
15 |
| - DrawTitle(); |
16 |
| - DrawTextArea(); |
| 17 | + DrawTitle(ref position); |
| 18 | + DrawTextArea(ref position, property); |
17 | 19 |
|
18 | 20 | property.serializedObject.ApplyModifiedProperties();
|
19 | 21 | }
|
20 |
| - private void DrawTitle() |
| 22 | + private void DrawTitle(ref Rect rect) |
21 | 23 | {
|
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; |
23 | 27 | }
|
24 |
| - private void DrawTextArea() |
| 28 | + private void DrawTextArea(ref Rect rect, SerializedProperty property) |
25 | 29 | {
|
26 |
| - SerializedProperty stringValue = _property.FindPropertyRelative("_value"); |
| 30 | + SerializedProperty stringValue = property.FindPropertyRelative("_value"); |
27 | 31 |
|
28 | 32 | 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; |
35 | 34 |
|
| 35 | + EditorGUI.indentLevel++; |
| 36 | + stringValue.stringValue = EditorGUI.TextArea(rect, stringValue.stringValue, Styles.TextAreaStyle); |
36 | 37 | EditorGUI.indentLevel--;
|
37 | 38 |
|
38 |
| - |
39 |
| - HandleInput(textAreaRect); |
| 39 | + HandleInput(rect, property); |
40 | 40 | }
|
41 |
| - private void HandleInput(Rect textAreaRect) |
| 41 | + private void HandleInput(Rect textAreaRect, SerializedProperty property) |
42 | 42 | {
|
43 | 43 | Event e = Event.current;
|
44 | 44 |
|
45 | 45 | if(e.type == EventType.MouseDown)
|
46 | 46 | {
|
47 | 47 | if (!textAreaRect.Contains(e.mousePosition))
|
48 |
| - RemoveFocus(); |
| 48 | + RemoveFocus(property); |
49 | 49 | }
|
50 | 50 | else if(e.type == EventType.KeyDown || e.type == EventType.KeyUp)
|
51 | 51 | {
|
52 | 52 | if (Event.current.keyCode == (KeyCode.Escape))
|
53 | 53 | {
|
54 |
| - RemoveFocus(); |
| 54 | + RemoveFocus(property); |
55 | 55 | }
|
56 | 56 | }
|
57 | 57 | }
|
58 |
| - private void RemoveFocus() |
| 58 | + private void RemoveFocus(SerializedProperty property) |
59 | 59 | {
|
60 | 60 | GUI.FocusControl(null);
|
61 |
| - Repaint(); |
| 61 | + Repaint(property); |
62 | 62 | }
|
63 |
| - private void Repaint() |
| 63 | + private void Repaint(SerializedProperty property) |
64 | 64 | {
|
65 |
| - EditorUtility.SetDirty(_property.serializedObject.targetObject); |
| 65 | + EditorUtility.SetDirty(property.serializedObject.targetObject); |
66 | 66 | }
|
67 | 67 | private static class Styles
|
68 | 68 | {
|
|
0 commit comments