Skip to content

Commit 8ec8e87

Browse files
committed
fix: ReadOnly attribute now works for TextArea fields
1 parent 97cd470 commit 8ec8e87

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

Assets/Mirror/Editor/ReadOnlyDrawer.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,35 @@
33

44
namespace Mirror
55
{
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+
620
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
721
public class ReadOnlyDrawer : PropertyDrawer
822
{
923
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
1024
{
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+
}
1329

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);
1734
}
1835
}
36+
1937
}

0 commit comments

Comments
 (0)