// Checked before OnGUI() public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { if (!allAttributes.NotNullOrEmpty()) { allAttributes = fieldInfo.GetCustomAttributes(typeof(PropertyAttribute), false).Cast <PropertyAttribute>() .ToList(); } if (allAttributes.Count > 1) { if (hideIfNotEnumAttr == null) { hideIfNotEnumAttr = allAttributes.Find(attr => attr is HideIfNotEnumValuesAttribute) as HideIfNotEnumValuesAttribute; } // skip drawing if not highest order (one-time draw execution check) if (!attribute.HasHighestOrder(allAttributes)) { // removes empty space instead of "not drawn" property return(-EditorGUIUtility.standardVerticalSpacing); } return(HideIfNotEnumValuesPropertyDrawer.IsAllowed(hideIfNotEnumAttr, property) ? EditorGUI.GetPropertyHeight(property, label) // removes empty space instead of "not drawn" property : -EditorGUIUtility.standardVerticalSpacing); } return(EditorGUI.GetPropertyHeight(property, label)); }
public static bool IsAllowed(HideIfNotEnumValuesAttribute attr, SerializedProperty property) { var propertyPath = property.propertyPath; var enumPath = propertyPath.Replace(property.name, attr.propertyName); // find enum value through our property object var enumProperty = property.serializedObject.FindProperty(enumPath); var enumIndex = enumProperty?.enumValueIndex; return(IsSupportedPropertyType(enumProperty) && attr.enumValues.Contains((int)enumIndex)); }