- Home /
SerializeFIeld in custom attribute
Is there a way to get the [SerializeField] functionality in custom attribute? Either by inheritance or with some code inside? I couldn't find it anywhere
I want to add it to this attribute which makes field readonly in the inspector:
using UnityEngine;
using UnityEditor;
public class ReadOnlyAttribute : PropertyAttribute
{ }
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
public class ReadOnlyDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property, label, true);
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
GUI.enabled = false;
EditorGUI.PropertyField(position, property, label, true);
GUI.enabled = true;
}
}
Comment
Your answer
Follow this Question
Related Questions
Unity Inspector batching Custom Property Attributes in Arrays 1 Answer
Some public attributes not shown in inspector, default references 3 Answers
Can a GameObject's full inspector be drawn in a custom Editor Window ? 1 Answer
Make popup window in inspector if deleting GameObject 0 Answers
Drop down with sizes 1 Answer