private bool GetConditionalHideAttributeResult(ConditionalHideAttribute condHAtt, SerializedProperty property) { bool enabled = true; //Look for the sourcefield within the object that the property belongs to 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) { enabled = condHAtt.Inverse ? !sourcePropertyValue.boolValue : sourcePropertyValue.boolValue; } else { Debug.LogWarning("Attempting to use a ConditionalHideAttribute but no matching SourcePropertyValue found in object: " + condHAtt.ConditionalSourceField); } return(enabled); }
private bool GetConditionalHideAttributeResult(ConditionalHideAttribute condHAtt, SerializedProperty property) { bool enabled = true; //Look for the sourcefield within the object that the property belongs to 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) { var data = sourcePropertyValue.GetCurrent(); if (data != null) { string valueStr = data.ToString(); if (!condHAtt.Split) { enabled = stringCheck(valueStr, condHAtt.ConditionalValueString, condHAtt.Contain); } else { var splits = valueStr.Split(condHAtt.SplitString); enabled = splits.Any(r => stringCheck(r, condHAtt.ConditionalValueString, condHAtt.Contain)); } } if (condHAtt.Inverse) { enabled = !enabled; } } else { if (!(enabled = condHAtt.ConditionalValueString.Equals("null") || condHAtt.ConditionalValueString.Equals("Null"))) { Debug.LogWarning("Attempting to use a ConditionalHideAttribute but no matching SourcePropertyValue found in object: " + condHAtt.ConditionalSourceField); } if (condHAtt.Inverse) { enabled = !enabled; } } return(enabled); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { ConditionalHideAttribute condHAtt = (ConditionalHideAttribute)attribute; bool bEnabled = GetConditionalHideAttributeResult(condHAtt, property); if (bEnabled || !condHAtt.HidenInspector) { Rect positionB = position; position.height = HeaderHeight; if (!string.IsNullOrEmpty(condHAtt.HeaderString)) { positionB.y += HeaderHeight; positionB.height -= HeaderHeight; EditorGUI.HelpBox(position, condHAtt.HeaderString, MessageType.Info); } bool bGUIEnabled = GUI.enabled; GUI.enabled = bEnabled; EditorGUI.PropertyField(positionB, property, label, true); GUI.enabled = bGUIEnabled; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { //get the attribute data ConditionalHideAttribute condHAtt = (ConditionalHideAttribute)attribute; //check if the propery we want to draw should be enabled bool enabled = GetConditionalHideAttributeResult(condHAtt, property); //Enable/disable the property bool wasEnabled = GUI.enabled; GUI.enabled = enabled; //Check if we should draw the property if (!condHAtt.HidenInspector || enabled) { EditorGUI.PropertyField(position, property, label, true); } //Ensure that the next property that is being drawn uses the correct settings GUI.enabled = wasEnabled; }