using UnityEngine;
using UnityEditor;
public class ReadOnlyAttribute : PropertyAttribute
{
}
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
public class ReadOnlyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var previousGUIState = GUI.enabled;
GUI.enabled = false;
EditorGUI.PropertyField(position, property, label);
GUI.enabled = previousGUIState;
}
}
Unity 创建Attribute实现只读PropertyDrawer
于 2024-10-11 13:55:28 首次发布