Exemplo n.º 1
0
        /// <summary>
        /// Draw property
        /// </summary>
        /// <param name="position"></param>
        /// <param name="property"></param>
        /// <param name="label"></param>
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            label = GetLabel(label);

            if (property.propertyType == SerializedPropertyType.Generic && GenericDrawer != null)
            {
                GenericDrawer.OnGUI(position, property, label);
                return;
            }

            // Use default property drawer.
            Dictionary <string, PropertyDrawer> s_dictionary = typeof(PropertyDrawer).GetField("s_PropertyDrawers", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).GetValue(null) as Dictionary <string, PropertyDrawer>;

            foreach (KeyValuePair <string, PropertyDrawer> entry in s_dictionary)
            {
                if (entry.Value == this)
                {
                    // Remove this property drawer.
                    s_dictionary[entry.Key] = null;
                    EditorGUI.PropertyField(position, property, label, true);
                    s_dictionary[entry.Key] = this;
                    return;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Current height of this property.
        /// </summary>
        /// <param name="property"></param>
        /// <param name="label"></param>
        /// <returns></returns>
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            if (property.propertyType == SerializedPropertyType.Generic && GenericDrawer != null)
            {
                return(GenericDrawer.GetPropertyHeight(property, label));
            }

            //Get the base height when not expanded
            float height = base.GetPropertyHeight(property, label);

            // if the property is expanded go through all its children and get their height
            if (property.isExpanded)
            {
                IEnumerator propEnum = property.GetEnumerator();
                while (propEnum.MoveNext())
                {
                    height += EditorGUI.GetPropertyHeight(( SerializedProperty )propEnum.Current, GUIContent.none, true);
                }
            }

            return(height);
        }