예제 #1
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            StringListPopup condHAtt = (StringListPopup)attribute;
            bool            enabled  = GetConditionalHideAttributeResult(condHAtt, property);

            if (!condHAtt.hideInInspector || enabled)
            {
                return(EditorGUI.GetPropertyHeight(property, label));
            }
            else
            {
                return(-EditorGUIUtility.standardVerticalSpacing);
            }
        }
예제 #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            StringListPopup condHAtt = (StringListPopup)attribute;
            bool            enabled  = GetConditionalHideAttributeResult(condHAtt, property);

            bool wasEnabled = GUI.enabled;

            GUI.enabled = enabled;
            if (!condHAtt.hideInInspector || enabled)
            {
                var list  = condHAtt.list;
                int index = Mathf.Max(0, Array.IndexOf(list, property.stringValue));
                index = EditorGUI.Popup(position, property.displayName, index, list);
                property.stringValue = list [index];
            }
            GUI.enabled = wasEnabled;
        }
예제 #3
0
        private bool GetConditionalHideAttributeResult(StringListPopup condHAtt, SerializedProperty property)
        {
            bool               enabled             = true;
            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)
            {
                if (condHAtt.reverseCondition)
                {
                    if (sourcePropertyValue.stringValue != condHAtt.conditionalString)
                    {
                        enabled = true;
                    }
                    else
                    {
                        enabled = false;
                    }
                }
                else
                {
                    if (sourcePropertyValue.stringValue != condHAtt.conditionalString)
                    {
                        enabled = false;
                    }
                    else
                    {
                        enabled = true;
                    }
                }
            }
            else
            {
                if (condHAtt.conditionalSourceField != "")
                {
                    Debug.LogWarning("Attempting to use a ConditionalHideAttribute but no matching SourcePropertyValue found in object: " + condHAtt.conditionalSourceField);
                }
            }
            return(enabled);
        }