Ejemplo n.º 1
0
        public static float GetPropertyHeight(GUIContent label, PersistentProperty property, bool includeChildren)
        {
            var height         = 0f;
            var propertyType   = property.type;
            var propertyDrawer = UserDatabase.caches.GetPropertyDrawer(propertyType);

            if (propertyDrawer != null)
            {
                height += propertyDrawer.GetHeight(property, label);
            }
            else if (UserDatabase.caches.IsDefaultPropertyType(propertyType))
            {
                return(GetDefaultTypeHeight(label, propertyType));
            }
            else
            {
                height += EditorGUIUtility.singleLineHeight;
                var foldout = UserDatabase.caches.GetPropertyFoldout(property);
                if (property.exist && includeChildren && foldout)
                {
                    var children = property.ListChildren();
                    foreach (var child in children)
                    {
                        var childLabel = new GUIContent(child.displayName);
                        height += EditorGUIUtility.standardVerticalSpacing;
                        height += GetPropertyHeight(childLabel, child, true);
                    }
                }
            }

            return(height);
        }
Ejemplo n.º 2
0
        public static void PropertyField(Rect position, GUIContent label, PersistentProperty property,
                                         bool includeChildren = false)
        {
            var propertyType = property.type;

            if (UserDatabase.caches.IsDefaultPropertyType(propertyType))
            {
                DefaultPropertyField(position, label, property);
            }
            else
            {
                var propertyRect = position;
                propertyRect.height = EditorGUIUtility.singleLineHeight;
                if (!property.exist)
                {
                    BeginColor(Color.yellow);
                    EditorGUI.LabelField(propertyRect, label, new GUIContent("NULL"));
                    EndColor();
                }
                else
                {
                    var propertyDrawer = UserDatabase.caches.GetPropertyDrawer(propertyType);
                    if (propertyDrawer != null)
                    {
                        propertyDrawer.OnGUI(position, property, label);
                    }
                    else
                    {
                        var foldout = EditorGUI.Foldout(propertyRect, UserDatabase.caches.GetPropertyFoldout(property),
                                                        label);
                        UserDatabase.caches.SetPropertyFoldout(property, foldout);
                        if (includeChildren && foldout)
                        {
                            propertyRect.y += EditorGUIUtility.singleLineHeight;
                            var children = property.ListChildren();
                            EditorGUI.indentLevel += 1;
                            foreach (var child in children)
                            {
                                var childLabel = new GUIContent(child.displayName);
                                propertyRect.y += EditorGUIUtility.standardVerticalSpacing;
                                PropertyField(propertyRect, childLabel, child, includeChildren);
                                propertyRect.y += GetPropertyHeight(childLabel, child, includeChildren);
                            }

                            EditorGUI.indentLevel -= 1;
                        }
                    }
                }
            }
        }