-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadOnlyAttribute.cs
More file actions
29 lines (24 loc) · 848 Bytes
/
ReadOnlyAttribute.cs
File metadata and controls
29 lines (24 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace RimuruDev
{
public sealed class ReadOnlyAttribute : PropertyAttribute { }
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
public sealed class ReadOnlyPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
SetGUIEnabled(isVisible: false);
DrawPropertyField(position, property, label);
SetGUIEnabled(isVisible: true);
}
private static void SetGUIEnabled(bool isVisible) =>
GUI.enabled = isVisible;
private static void DrawPropertyField(Rect position, SerializedProperty property, GUIContent label) =>
EditorGUI.PropertyField(position, property, label);
}
#endif
}