namespace UnityEngine { #if UNITY_EDITOR /// /// 设置属性只读 /// public class DisplayOnly : PropertyAttribute { } [UnityEditor.CustomPropertyDrawer(typeof(DisplayOnly))] public class ReadOnlyDrawer : UnityEditor.PropertyDrawer { public override float GetPropertyHeight(UnityEditor.SerializedProperty property, GUIContent label) { return UnityEditor.EditorGUI.GetPropertyHeight(property, label, true); } public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label) { GUI.enabled = false; UnityEditor.EditorGUI.PropertyField(position, property, label, true); GUI.enabled = true; } } #endif }