|
3 | 3 |
|
4 | 4 | namespace Mirror |
5 | 5 | { |
| 6 | + //[CustomPropertyDrawer(typeof(ReadOnlyAttribute))] |
| 7 | + //public class ReadOnlyDrawer : PropertyDrawer |
| 8 | + //{ |
| 9 | + // public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) |
| 10 | + // { |
| 11 | + // // Cache the current GUI enabled state |
| 12 | + // bool prevGuiEnabledState = GUI.enabled; |
| 13 | + |
| 14 | + // GUI.enabled = false; |
| 15 | + // EditorGUI.PropertyField(position, property, label, true); |
| 16 | + // GUI.enabled = prevGuiEnabledState; |
| 17 | + // } |
| 18 | + //} |
| 19 | + |
6 | 20 | [CustomPropertyDrawer(typeof(ReadOnlyAttribute))] |
7 | 21 | public class ReadOnlyDrawer : PropertyDrawer |
8 | 22 | { |
9 | 23 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) |
10 | 24 | { |
11 | | - // Cache the current GUI enabled state |
12 | | - bool prevGuiEnabledState = GUI.enabled; |
| 25 | + EditorGUI.BeginDisabledGroup(true); |
| 26 | + EditorGUI.PropertyField(position, property, label, true); // 'true' lets TextArea expand |
| 27 | + EditorGUI.EndDisabledGroup(); |
| 28 | + } |
13 | 29 |
|
14 | | - GUI.enabled = false; |
15 | | - EditorGUI.PropertyField(position, property, label, true); |
16 | | - GUI.enabled = prevGuiEnabledState; |
| 30 | + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) |
| 31 | + { |
| 32 | + // Let Unity compute the proper height (needed for TextArea) |
| 33 | + return EditorGUI.GetPropertyHeight(property, label, true); |
17 | 34 | } |
18 | 35 | } |
| 36 | + |
19 | 37 | } |
0 commit comments