public static bool PropertyIsVisible(SerializedProperty property, bool inverse, string[] compareAgainst) { if (property == null) { return(true); } string asString = property.AsStringValue().ToUpper(); if (compareAgainst != null && compareAgainst.Length > 0) { var matchAny = CompareAgainstValues(asString, compareAgainst); if (inverse) { matchAny = !matchAny; } return(matchAny); } bool someValueAssigned = asString != "FALSE" && asString != "0" && asString != "NULL"; if (someValueAssigned) { return(!inverse); } return(inverse); }
private bool GetConditionalHideAttributeResult(ConditionalHideAttribute condHAtt, SerializedProperty property) { bool enabled = false; string propertyPath = property.propertyPath; //returns the property path of the property we want to apply the attribute to string conditionPath = propertyPath.Replace(property.name, condHAtt.ConditionalSourceField); //changes the path to the conditionalsource property path SerializedProperty sourcePropertyValue = property.serializedObject.FindProperty(conditionPath); if (sourcePropertyValue == null) { Debug.LogWarning("Attempting to use a ConditionalHideAttribute but no matching SourcePropertyValue found in object: " + condHAtt.ConditionalSourceField); return(enabled); } enabled = sourcePropertyValue.boolValue; if (condHAtt.CompareValues != null && condHAtt.CompareValues.Length > 0) { enabled = false; for (var i = 0; i < condHAtt.CompareValues.Length; i++) { if (condHAtt.CompareValues[i] == sourcePropertyValue.AsStringValue().ToUpper()) { enabled = true; break; } } } return(enabled); }
public static bool PropertyIsVisible(SerializedProperty property, bool inverse, string[] compareAgainst) { if (property == null) { return(true); } string asString = property.AsStringValue().ToUpper(); if (compareAgainst != null && compareAgainst.Length > 0) { var matchAny = CompareAgainstValues(asString, compareAgainst, IsFlagsEnum()); if (inverse) { matchAny = !matchAny; } return(matchAny); } bool someValueAssigned = asString != "FALSE" && asString != "0" && asString != "NULL"; if (someValueAssigned) { return(!inverse); } return(inverse); bool IsFlagsEnum() { if (property.propertyType != SerializedPropertyType.Enum) { return(false); } var value = property.GetValue(); if (value == null) { return(false); } return(value.GetType().GetCustomAttribute <FlagsAttribute>() != null); } }