Esempio n. 1
0
        /// <summary>
        /// Override the get height method
        /// </summary>
        /// <param name="property"></param>
        /// <param name="label"></param>
        /// <returns></returns>
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            //Get display attribute
            DisplayIfAttribute displayAttribute = (DisplayIfAttribute)attribute;
            bool enabled = displayAttribute.ShouldDisplay(property.serializedObject);
            int  rows    = 1;

            //Special case for expandable entries
            if (property.isArray)
            {
                rows = property.arraySize + 1;
            }
            else if (property.propertyType == SerializedPropertyType.Rect || property.propertyType == SerializedPropertyType.Vector4)
            {
                rows = 6;
            }

            if (enabled)
            {
                return(base.GetPropertyHeight(property, label) * (property.isExpanded ? rows : 1));
            }
            else
            {
                return(0f);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Draw the inspector
        /// </summary>
        /// <param name="position"></param>
        /// <param name="property"></param>
        /// <param name="label"></param>
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            label = EditorGUI.BeginProperty(position, label, property);

            //Get display attribute
            DisplayIfAttribute displayAttribute = (DisplayIfAttribute)attribute;
            bool enabled = displayAttribute.ShouldDisplay(property.serializedObject);

            //Enable/disable the property
            bool wasEnabled = GUI.enabled;

            GUI.enabled = enabled;

            EditorGUI.BeginChangeCheck();

            if (enabled)
            {
                EditorGUI.PropertyField(position, property, label, true);
            }

            EditorGUI.EndChangeCheck();

            //Ensure that the next property that is being drawn uses the correct settings
            GUI.enabled = wasEnabled;

            EditorGUI.EndProperty();
        }