Beispiel #1
0
    private bool GetConditionalHideAttributeResult(ConditionalHideInspectorAttribute chiAttribute, SerializedProperty property)
    {
        bool enabled = true;
        SerializedProperty sourcePropertyValue = property.serializedObject.FindProperty(chiAttribute.ConditionalSourceField);

        if (sourcePropertyValue != null)
        {
            enabled = CheckPropertyType(sourcePropertyValue);
        }
        else
        {
            Debug.LogWarning("Attempting to use a ConditionalHideAttribute but no matching SourcePropertyValue found in object: " + chiAttribute.ConditionalSourceField);
        }

        SerializedProperty sourcePropertyValue2 = property.serializedObject.FindProperty(chiAttribute.ConditionalSourceField2);

        if (sourcePropertyValue2 != null)
        {
            enabled = enabled && CheckPropertyType(sourcePropertyValue2);
        }
        else
        {
            //Debug.LogWarning("Attempting to use a ConditionalHideAttribute but no matching SourcePropertyValue found in object: " + chiAttribute.ConditionalSourceField);
        }

        if (chiAttribute.Inverse)
        {
            enabled = !enabled;
        }

        return(enabled);
    }
Beispiel #2
0
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        ConditionalHideInspectorAttribute chiAttribute = (ConditionalHideInspectorAttribute)attribute;
        bool enabled = GetConditionalHideAttributeResult(chiAttribute, property);

        if (!chiAttribute.HideInInspector || enabled)
        {
            return(EditorGUI.GetPropertyHeight(property, label));
        }
        else
        {
            //The property is not being drawn
            //We want to undo the spacing added before and after the property
            return(-EditorGUIUtility.standardVerticalSpacing);
            //return 0.0f;
        }

        /*
         * //Get the base height when not expanded
         * var height = base.GetPropertyHeight(property, label);
         *
         * // if the property is expanded go thru all its children and get their height
         * if (property.isExpanded)
         * {
         *  var propEnum = property.GetEnumerator();
         *  while (propEnum.MoveNext())
         *      height += EditorGUI.GetPropertyHeight((SerializedProperty)propEnum.Current, GUIContent.none, true);
         * }
         * return height;
         */
    }
Beispiel #3
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        ConditionalHideInspectorAttribute chiAttribute = (ConditionalHideInspectorAttribute)attribute;
        bool enabled = GetConditionalHideAttributeResult(chiAttribute, property);

        bool wasEnabled = GUI.enabled;

        GUI.enabled = enabled;
        if (!chiAttribute.HideInInspector || enabled)
        {
            EditorGUI.PropertyField(position, property, label, true);
        }

        GUI.enabled = wasEnabled;
    }