- Home /
Question by
dyllandry · Mar 10, 2019 at 09:28 PM ·
c#editorcustom editorattributeproperty drawer
Min Attribute Not Working on Custom Property Drawer
Here's my data structure. The range attribute works, but not the min attribute.
[System.Serializable]
public struct CreatureTableEntry {
public Creature creature;
[Min(1)]
public int level;
[Range(0, 1)]
public float probability;
}
If it is helpful, here is my property drawer file
[CustomPropertyDrawer(typeof(CreatureTableEntry))]
public class CreatureTableEntryDrawer : PropertyDrawer {
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
Rect creatureRect = new Rect(position.x, position.y, 150, position.height);
Rect levelRect = new Rect(position.x + 155, position.y, 45, position.height);
Rect probabilityRect = new Rect(position.x + 205, position.y, 65, position.height);
EditorGUI.PropertyField(creatureRect, property.FindPropertyRelative("creature"), GUIContent.none);
EditorGUI.PropertyField(levelRect, property.FindPropertyRelative("level"), GUIContent.none);
EditorGUI.PropertyField(probabilityRect, property.FindPropertyRelative("probability"), GUIContent.none);
}
}
Comment
I would like an answer to this as well. I am making a custom editor for a MonoBehaviour using UI Toolkit and the Min, Range, etc attributes on field do not work.