Home > Software design >  My variable are hidden in my custom inspector (PropertyDrawer)
My variable are hidden in my custom inspector (PropertyDrawer)

Time:07-01

I'm going straight to the point! I'm using an enumerator to try to choose the variables I want to display, but for some reason the variables are not visible (half visible)

An example of the problem

So, here is the part of the code that allows me to display and choose which variable to display :

[CustomPropertyDrawer(typeof(QuestGoal))]
public class QuestGoal_PropertyDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        SerializedProperty questType = property.FindPropertyRelative("questType");
        SerializedProperty item = property.FindPropertyRelative("item");
        SerializedProperty currentAmount = property.FindPropertyRelative("currentAmount");
        SerializedProperty totalAmount = property.FindPropertyRelative("totalAmount");
        SerializedProperty positionQuest = property.FindPropertyRelative("positionQuest");

        float lineHeight = EditorGUIUtility.singleLineHeight;

        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
        EditorGUI.PropertyField(position, questType, GUIContent.none);


        switch (questType.intValue)
        {
            case (int)QuestType.CRAFTING:
                position = new Rect(position.x, position.y   lineHeight, position.width, position.height);
                EditorGUI.PropertyField(position, item);
                break;
            case (int)QuestType.GATHERING:
                position = new Rect(position.x, position.y   lineHeight, position.width, position.height);
                EditorGUI.PropertyField(position, currentAmount);
                position = new Rect(position.x, position.y   lineHeight * 2, position.width, position.height);
                EditorGUI.PropertyField(position, totalAmount);
                break;
            case (int)QuestType.JOURNEY:
                position = new Rect(position.x, position.y   lineHeight, position.width, position.height);
                EditorGUI.PropertyField(position, positionQuest);
                break;
            default:
                break;
        }

        EditorGUI.EndProperty();
    }
}

The switch allows me to choose my variables but there values ​​after the enumerator are still hidden

CodePudding user response:

you need to implement:

        public override float GetPropertyHeight( SerializedProperty property, GUIContent label )

so the editor knows how much space to reserve for your property. Now you got the default height (probably EditorGUIUtility.singleLineHeight) and you need more so your property is clipped

  • Related