示例#1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            BoolConditionalHide condHAtt = (BoolConditionalHide)attribute;
            bool enabled    = GetConditionalHideAttributeResult(condHAtt, property);
            bool wasEnabled = GUI.enabled;

            GUI.enabled = enabled;
            if (!condHAtt.HideInInspector || enabled)
            {
                EditorGUI.PropertyField(position, property, label, true);
            }
            GUI.enabled = wasEnabled;
        }
示例#2
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            BoolConditionalHide condHAtt = (BoolConditionalHide)attribute;
            bool enabled = GetConditionalHideAttributeResult(condHAtt, property);

            if (!condHAtt.HideInInspector || enabled)
            {
                return(EditorGUI.GetPropertyHeight(property, label));
            }
            else
            {
                return(-EditorGUIUtility.standardVerticalSpacing);
            }
        }
示例#3
0
        private bool GetConditionalHideAttributeResult(BoolConditionalHide condHAtt, SerializedProperty property)
        {
            bool               enabled             = true;
            string             propertyPath        = property.propertyPath;
            string             conditionPath       = propertyPath.Replace(property.name, condHAtt.ConditionalSourceField);
            SerializedProperty sourcePropertyValue = property.serializedObject.FindProperty(conditionPath);

            if (sourcePropertyValue != null)
            {
                if (condHAtt.reverseCondition)
                {
                    if (sourcePropertyValue.boolValue == false)
                    {
                        enabled = true;
                    }
                    else
                    {
                        enabled = false;
                    }
                }
                else
                {
                    if (sourcePropertyValue.boolValue == false)
                    {
                        enabled = false;
                    }
                    else
                    {
                        enabled = true;
                    }
                }
            }
            else
            {
                Debug.LogWarning("Attempting to use a ConditionalHideAttribute but no matching SourcePropertyValue found in object: " + condHAtt.ConditionalSourceField);
            }
            return(enabled);
        }