Example #1
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            ShowIfAttribute show = (ShowIfAttribute)attribute;

            if (Show(property))
            {
                return(EditorGUI.GetPropertyHeight(property, label, true));
            }
            else
            {
                return(0);
            }
            //-EditorGUI.GetPropertyHeight(property, label, true);
        }
Example #2
0
        private bool Show(SerializedProperty property)
        {
            showIf        = attribute as ShowIfAttribute;
            comparedField = property.serializedObject.FindProperty(showIf.comparedPropertyName);

            string path = property.propertyPath.Contains(".") ? System.IO.Path.ChangeExtension(property.propertyPath, showIf.comparedPropertyName) : showIf.comparedPropertyName;
            object comparedFieldValue = property.serializedObject.FindProperty(path);

            // object comparedFieldValue = (object)comparedField.objectReferenceValue;

            switch (comparedField.type)
            { // Possible extend cases to support your own type
            case "bool":

                if (comparedField.boolValue.Equals(showIf.comparedValue))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            case "Enum":

                if (comparedField.enumValueIndex.Equals((int)showIf.comparedValue))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            case "int":
                if (comparedField.intValue.Equals(showIf.comparedValue))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            case "float":
                if (comparedField.floatValue.Equals(showIf.comparedValue))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            case "string":
                if (comparedField.stringValue.Equals(showIf.comparedValue))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            default:
                Debug.LogError($"Error: {comparedField.type} Is not supported");
                return(true);
            }
        }