0%

代码禁用属性面板

用于禁用公开的对象在面板的参数改变

img

禁用状态和非禁用状态展示

禁用代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#region 禁用面板
/// <summary>
/// 禁用面板特性
/// </summary>
public class DisplayOnly : PropertyAttribute
{

}
[CustomPropertyDrawer(typeof(DisplayOnly))]
public class ReadOnlyDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property, label, true);
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
GUI.enabled = false;
EditorGUI.PropertyField(position, property, label, true);
GUI.enabled = true;
}
}
#endregion

如何使用

1
2
[DisplayOnly]
public GameObject obj;