2020-03-01 21:32:52 +01:00
using UnityEngine ;
using UnityEditor ;
namespace UnityAtoms.Editor
{
/// <summary>
/// Make property read only by using the abbtribute `[ReadOnly]`. Solution taken from: https://answers.unity.com/questions/489942/how-to-make-a-readonly-property-in-inspector.html
/// </summary>
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
public class ReadOnlyDrawer : PropertyDrawer
{
public override float GetPropertyHeight ( SerializedProperty property ,
2020-03-21 22:45:39 +01:00
GUIContent label )
2020-03-01 21:32:52 +01:00
{
return EditorGUI . GetPropertyHeight ( property , label , true ) ;
}
public override void OnGUI ( Rect position ,
2020-03-21 22:45:39 +01:00
SerializedProperty property ,
GUIContent label )
2020-03-01 21:32:52 +01:00
{
GUI . enabled = false ;
EditorGUI . PropertyField ( position , property , label , true ) ;
GUI . enabled = true ;
}
}
}