커스텀 Attribute를 통해 Unity 인스펙터에서 특정 필드를 읽기 전용으로 표시하기 위한 기능
using UnityEngine;
public class InspectorReadOnlyAttribute : PropertyAttribute { }
[InspectorReadOnly] 붙이기 위해 존재PropertyAttribute 상속Unity에서 필드의 인스펙터 표시 방식을 제어하기 위한 기본 클래스
using UnityEditor;
using UnityEngine;
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(InspectorReadOnlyAttribute))]
public class InspectorReadOnlyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
GUI.enabled = false;
EditorGUI.PropertyField(position, property, label, true);
GUI.enabled = true;
}
}
#endif
CustomPropertyDrawer를 통해 InspectorReadOnlyAttribute가 붙은 필드에만 작동OnGUI 내부에서 GUI.enabled = false로 설정하여 입력을 막고, 이후 복원