Пример #1
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        ShowOnEnum         att          = attribute as ShowOnEnum;
        SerializedProperty enumProperty = property.serializedObject.FindProperty(att.enumName);

        if (enumProperty.enumValueIndex == att.wantedValue)
        {
            EditorGUI.PropertyField(position, property, label, true);
        }
    }
Пример #2
0
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        ShowOnEnum         att          = attribute as ShowOnEnum;
        SerializedProperty enumProperty = property.serializedObject.FindProperty(att.enumName);

        if (enumProperty.enumValueIndex != att.wantedValue)
        {
            return(-2f);
        }

        return(EditorGUI.GetPropertyHeight(property));
    }
Пример #3
0
    public override float GetPropertyHeight(SerializedProperty _property, GUIContent _label)
    {
        ShowOnEnum showInInspector = (ShowOnEnum)attribute;
        bool       enabled         = ShouldShow(showInInspector, _property);

        if (enabled)
        {
            return(EditorGUI.GetPropertyHeight(_property, _label));
        }
        else
        {
            return(-EditorGUIUtility.standardVerticalSpacing);
        }
    }
Пример #4
0
    public override void OnGUI(Rect _position, SerializedProperty _property, GUIContent _label)
    {
        ShowOnEnum showInInspector = (ShowOnEnum)attribute;
        bool       enabled         = ShouldShow(showInInspector, _property);
        bool       wasEnabled      = GUI.enabled;

        GUI.enabled = enabled;
        if (enabled)
        {
            ++EditorGUI.indentLevel;
            EditorGUI.PropertyField(_position, _property, _label, true);
            --EditorGUI.indentLevel;
        }

        GUI.enabled = wasEnabled;
    }
Пример #5
0
    private bool ShouldShow(ShowOnEnum _attribute, SerializedProperty _property)
    {
        bool               enabled             = true;
        string             propertyPath        = _property.propertyPath;
        string             conditionPath       = propertyPath.Replace(_property.name, _attribute.conditionalSourceField);
        SerializedProperty sourcePropertyValue = _property.serializedObject.FindProperty(conditionPath);

        if (sourcePropertyValue != null)
        {
            enabled = sourcePropertyValue.enumValueIndex == _attribute.compare;
        }
        else
        {
            Debug.LogWarning("Attempting to use ShowOnEnumValue but no matching SourcePropertyValue found in object: " + _attribute.conditionalSourceField);
        }

        return(enabled);
    }