I’ve run into an issue and I don’t know if its a bug or something wrong with my code.
But basically I cannot click or expand any selection fields that are not generated as children in a property field.
This happens with Popups, Foldout and Foldout Header Groups. Clicking on them does nothing.
I really don’t know what I’ve done wrong here:
[CustomPropertyDrawer(typeof(Criteria))]
public class CriteriaPropertyDrawer : PropertyDrawer
{
public Type[] _criteriaTypes;
public string[] _criteriaTypeNames;
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property, label);
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
EditorGUI.PropertyField(position, property, label, true);
position.y += EditorGUI.GetPropertyHeight(property);
GetCriteriaList();
EditorGUI.BeginChangeCheck();
EditorGUI.indentLevel++;
int index = EditorGUI.Popup(position, "Criteria Type", -1, _criteriaTypeNames);
if (EditorGUI.EndChangeCheck())
{
Debug.Log($"Chosen index {index}");
}
EditorGUI.indentLevel--;
EditorGUI.EndProperty();
}
private void GetCriteriaList()
{
if (_criteriaTypes == null)
{
_criteriaTypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(a => a.GetTypes())
.Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(Criteria)))
.ToArray();
_criteriaTypeNames = _criteriaTypes.Select(t => t.Name).ToArray();
}
}
}
I’m on Unity 2021.2.7f1