代码禁用属性面板

 1 #region 禁用面板
 2   /// <summary>
 3   /// 禁用面板特性
 4   /// </summary>
 5   public class DisplayOnly : PropertyAttribute
 6   {
 7 
 8   }
 9   [CustomPropertyDrawer(typeof(DisplayOnly))]
10   public class ReadOnlyDrawer : PropertyDrawer
11   {
12       public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
13       {
14           return EditorGUI.GetPropertyHeight(property, label, true);
15       }
16       public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
17       {
18           GUI.enabled = false;
19           EditorGUI.PropertyField(position, property, label, true);
20           GUI.enabled = true;
21       }
22   }
23   #endregion

如何使用

[DisplayOnly]
public GameObject obj;

 

posted @ 2022-07-12 17:07  枫亦  阅读(7)  评论(0)    收藏  举报