private int GetConditionalHideAttributeResult(ConditionalEnumHideAttribute condHAtt, SerializedProperty property) { int enumValue = 0; SerializedProperty sourcePropertyValue = null; if (!property.isArray) { string propertyPath = property.propertyPath; string conditionPath = propertyPath.Replace(property.name, condHAtt.ConditionalSourceField); sourcePropertyValue = property.serializedObject.FindProperty(conditionPath); if (sourcePropertyValue == null) { sourcePropertyValue = property.serializedObject.FindProperty(condHAtt.ConditionalSourceField); } } else { sourcePropertyValue = property.serializedObject.FindProperty(condHAtt.ConditionalSourceField); } if (sourcePropertyValue != null) { enumValue = sourcePropertyValue.enumValueIndex; } return(enumValue); }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { ConditionalEnumHideAttribute condHAtt = (ConditionalEnumHideAttribute)attribute; int enumValue = GetConditionalHideAttributeResult(condHAtt, property); if (!condHAtt.HideInInspector || (condHAtt.EnumValue1 == enumValue) || (condHAtt.EnumValue2 == enumValue)) { return(EditorGUI.GetPropertyHeight(property, label)); } else { return(-EditorGUIUtility.standardVerticalSpacing); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { ConditionalEnumHideAttribute condHAtt = (ConditionalEnumHideAttribute)attribute; int enumValue = GetConditionalHideAttributeResult(condHAtt, property); bool wasEnabled = GUI.enabled; GUI.enabled = ((condHAtt.EnumValue1 == enumValue) || (condHAtt.EnumValue2 == enumValue)); if (!condHAtt.HideInInspector || (condHAtt.EnumValue1 == enumValue) || (condHAtt.EnumValue2 == enumValue)) { EditorGUI.PropertyField(position, property, label, true); } GUI.enabled = wasEnabled; }
private int GetConditionalHideAttributeResult(ConditionalEnumHideAttribute condHAtt, SerializedProperty property) { int enumValue = 0; SerializedProperty sourcePropertyValue = null; //Get the full relative property path of the sourcefield so we can have nested hiding if (!property.isArray) { 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 sourcePropertyValue = property.serializedObject.FindProperty(conditionPath); //if the find failed->fall back to the old system if (sourcePropertyValue == null) { //original implementation (doens't work with nested serializedObjects) sourcePropertyValue = property.serializedObject.FindProperty(condHAtt.ConditionalSourceField); } } else { //original implementation (doens't work with nested serializedObjects) sourcePropertyValue = property.serializedObject.FindProperty(condHAtt.ConditionalSourceField); } if (sourcePropertyValue != null) { enumValue = sourcePropertyValue.enumValueIndex; } else { //Debug.LogWarning("Attempting to use a ConditionalHideAttribute but no matching SourcePropertyValue found in object: " + condHAtt.ConditionalSourceField); } return(enumValue); }