Exemplo n.º 1
0
 public PropertyData(PropertyData parent, int index)
 {
     Index = index;
     Init(parent, parent.Property.GetArrayElementAtIndex(index));
 }
Exemplo n.º 2
0
        public override void Draw(PropertyData data)
        {
            var attr = data.Attributes.FirstOrDefault() as ListDrawerAttribute;

            if (attr == null)
            {
                attr = new ListDrawerAttribute();
            }

            Rect rect = EditorGUILayout.BeginVertical(Style.ListBackground);

            PerunEditor.DropRect dropRect = null;
            if (Event.current.type == EventType.Repaint)
            {
                dropRect          = Editor.CreateDropRect();
                dropRect.Position = rect;
                object objParent = data.Parent.Value;
                object obj       = data.Value;
                string path      = data.Property.propertyPath;
                dropRect.Validate = () => {
                    return(DropValidate(obj, path));// DragAndDrop.objectReferences.FirstOrDefault(e => e is type);
                };
                dropRect.Action = i => Drop(objParent, obj, path, i);
            }

            AnimBool animBool = Editor.GetAnimBool(data.Property.propertyPath, data.Property.isExpanded);

            // Header

            EditorGUILayout.BeginHorizontal(Style.Toolbar);

            //data.Property.isExpanded = EditorGUILayout.Foldout(data.Property.isExpanded, new GUIContent(data.Property.displayName));
            if (EditorGUILayout.DropdownButton(new GUIContent(data.Property.displayName), FocusType.Passive,
                                               data.Property.isExpanded ? Style.FoldoutExpanded : Style.Foldout))
            {
                data.Property.isExpanded = !data.Property.isExpanded;
            }

            //Foldout

            animBool.target = data.Property.isExpanded;

            EditorGUILayout.LabelField(data.Property != null && data.Property.arraySize > 0 ? data.Property.arraySize + " items" : "empty", Style.ToolbarLabelRight, GUILayout.Width(64));

            if (attr.ShowAddButton && GUILayout.Button("", Style.ToolbarAddButton, GUILayout.Width(18)))
            {
                data.AddNewItem();
                data.Property.serializedObject.ApplyModifiedProperties();
            }

            EditorGUILayout.EndHorizontal();
            //

            EditorGUILayout.BeginVertical(data.Property.isExpanded ? Style.ListContent : Style.ListContentEmpty);

            if (EditorGUILayout.BeginFadeGroup(animBool.faded))
            {
                for (int i = 0; i < data.Property.arraySize; i++)
                {
                    SerializedProperty itemProperty = data.Property.GetArrayElementAtIndex(i);

                    /*
                     * if(i > 0 && itemProperty.propertyType == SerializedPropertyType.Generic)
                     *  EditorGUILayout.Space();
                     */
                    Rect itemRect = EditorGUILayout.BeginHorizontal(Style.ListItem);
                    if (dropRect != null && data.Property.isExpanded)
                    {
                        dropRect.Childs.Add(new Rect(itemRect.x - 5, itemRect.y - 1, itemRect.width + 6, itemRect.height + 2));
                    }

                    if (attr.ShowDrag)
                    {
                        Rect itemDragRect = EditorGUILayout.GetControlRect(false, 10, Style.ListDragElement, GUILayout.Width(13));
                        itemDragRect = new Rect(itemDragRect.x, itemDragRect.y + itemRect.height / 2 - 12, 12, 16);
                        GUI.Box(itemDragRect, GUIContent.none, Style.ListDragElement);
                        itemDragRect = new Rect(itemDragRect.x, itemDragRect.y + 6, 12, 16);
                        GUI.Box(itemDragRect, GUIContent.none, Style.ListDragElement);

                        //GUI.Box(itemDragRect, GUIContent.none, Style.ListDragElement);
                        //EditorGUI.DropdownButton(itemDragRect, GUIContent.none, FocusType.Passive, Style.ListDragElement);

                        if (Event.current.type == EventType.Repaint)
                        {
                            PerunEditor.DragRect dragRect = Editor.CreateDragRect();
                            dragRect.Position = new Rect(itemDragRect.x - 3, itemRect.y, itemDragRect.width + 6, itemRect.height);
                            int    index = i;
                            string path  = data.Property.propertyPath;
                            object obj   = data.Value;
                            dragRect.Action = () =>
                            {
                                DragAndDrop.PrepareStartDrag();
                                DragAndDrop.SetGenericData("ListDragData", new DragData(Editor, path, index, obj, data.Value, data.Parent.Value));
                                DragAndDrop.StartDrag(itemProperty.propertyPath);
                            };
                        }
                    }

                    EditorGUILayout.BeginVertical();
                    Editor.Property.Draw(new PropertyData(data, i));
                    EditorGUILayout.EndVertical();
                    //DrawItem(attr, itemProperty, i, type, attrList, parent);
                    //
                    if (attr.ShowRemoveButton)
                    {
                        Rect deleteRect = EditorGUILayout.GetControlRect(false, 16, GUILayout.Width(16));
                        deleteRect = new Rect(deleteRect.x, deleteRect.y + itemRect.height / 2 - 10, 16, 16);

                        if (GUI.Button(deleteRect, GUIContent.none, Style.ListDeleteItem))
                        {
                            data.Property.DeleteArrayElementAtIndex(i);
                        }

                        /*
                         * if (GUILayout.Button("", Style.ListDeleteItem, GUILayout.Width(16)))
                         * {
                         * }*/
                    }

                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndFadeGroup();

            EditorGUILayout.EndVertical();
            //

            EditorGUILayout.EndVertical();
        }
Exemplo n.º 3
0
 private void Init(PropertyData parent, SerializedProperty property)
 {
     Childs   = new List <PropertyData>();
     Parent   = parent;
     Property = property;
 }
Exemplo n.º 4
0
 public PropertyData(SerializedProperty property, PropertyData parent)
 {
     Init(parent, property);
 }
Exemplo n.º 5
0
 public virtual void Draw(PropertyData data)
 {
 }
Exemplo n.º 6
0
        public override void Draw(PropertyData data)
        {
            bool visible = true;

            foreach (var attr in data.Attributes)
            {
                if (attr is VisibleAttribute)
                {
                    VisibleAttribute visibleAttr = attr as VisibleAttribute;
                    if (visibleAttr.Value == null)
                    {
                        bool visibleValue;
                        if (Utilities.GetValue(data.Parent.Value, visibleAttr.MemberName, out visibleValue))
                        {
                            visible = visible && (visibleAttr.IsNot ? !visibleValue : visibleValue);
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("VisibleAttribute: MemberName \"" + visibleAttr.MemberName + "\" not found!", MessageType.Error);
                        }
                    }
                }
            }
            if (!visible)
            {
                return;
            }


            switch (data.Type)
            {
            case PropertyData.Types.SelfDrawer:
                EditorGUILayout.PropertyField(data.Property, new GUIContent(data.Property.displayName));
                return;

            case PropertyData.Types.List:
                Editor.List.Draw(data);
                return;

            case PropertyData.Types.Generic:
                Editor.Generic.Draw(data);
                return;
            }

            if (data.Property.propertyType == SerializedPropertyType.Enum)
            {
                Editor.Enum.Draw(data);
                return;
            }

            GUIContent labelText = data.Attributes.Exists(e => e is HideLabelAttribute) ? GUIContent.none : new GUIContent(data.Property.displayName);

            EditorGUILayout.PropertyField(data.Property, labelText, true);

            /*
             * EditorGUILayout.BeginHorizontal();
             * EditorGUILayout.LabelField(data.Property.propertyPath.Replace(".Array.data[", "["));
             * EditorGUILayout.LabelField((data.Value != null ? data.Value.GetType().ToString() : "null"));
             * EditorGUILayout.EndHorizontal();
             *
             * if (data.Attributes != null)
             * {
             *      EditorGUI.indentLevel++;
             *      foreach (var a in data.Attributes)
             *      {
             *              EditorGUILayout.LabelField("A: " + a.GetType().ToString());
             *      }
             *      EditorGUI.indentLevel--;
             * }
             */
        }
Exemplo n.º 7
0
        public override void Draw(PropertyData data)
        {
            //data.Attributes.ForEach(a => EditorGUILayout.LabelField(a.GetType().FullName));
            bool isFlags = data.Attributes.Exists(e => e is FlagsAttribute);

            if (data.Attributes.Exists(e => e is EnumButtonsAttribute))
            {
                EditorGUILayout.BeginHorizontal();

                if (!data.Attributes.Exists(e => e is HideLabelAttribute))
                {
                    EditorGUILayout.LabelField(new GUIContent(data.Property.displayName), GUILayout.Width(EditorGUIUtility.labelWidth - 5));
                }

                Array list = Enum.GetValues(data.ValueType);
                if (list.Length > 0)
                {
                    int buttonsIntValue = data.Property.intValue;
                    int enumLength      = list.Length;

                    GUIStyle style = EditorStyles.miniButton;
                    for (int i = 0; i < enumLength; i++)
                    {
                        if (enumLength > 1)
                        {
                            if (i == 0)
                            {
                                style = EditorStyles.miniButtonLeft;
                            }
                            else if (i == enumLength - 1)
                            {
                                style = EditorStyles.miniButtonRight;
                            }
                            else
                            {
                                style = EditorStyles.miniButtonMid;
                            }
                        }

                        int  value     = (int)list.GetValue(i);
                        bool lastValue = isFlags && value != 0 ? (data.Property.intValue & value) == value : data.Property.intValue == value;

                        bool newValue = GUILayout.Toggle(lastValue, data.Property.enumDisplayNames[i], style);
                        if (newValue != lastValue)
                        {
                            if (isFlags && value != 0)
                            {
                                if (newValue)
                                {
                                    buttonsIntValue |= value;
                                }
                                else
                                {
                                    buttonsIntValue ^= value;
                                }
                            }
                            else
                            {
                                buttonsIntValue = value;
                            }

                            data.Property.intValue = buttonsIntValue;
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                GUIContent labelText = data.Attributes.Exists(e => e is HideLabelAttribute) ? GUIContent.none : new GUIContent(data.Property.displayName);
                if (isFlags)
                {
                    data.Value = EditorGUILayout.EnumFlagsField(labelText, (Enum)data.Value);
                }
                else
                {
                    EditorGUILayout.PropertyField(data.Property, labelText, true);
                }
            }
        }
Exemplo n.º 8
0
        public override void Draw(PropertyData data)
        {
            //data.Attributes.ForEach(a => EditorGUILayout.LabelField(a.GetType().FullName));
            StructDrawerAttribute attr = null;

            if (data.Parent != null && data.Parent.Type == PropertyData.Types.List)
            {
                attr = data.Parent.Attributes.FirstOrDefault(e => e is StructDrawerAttribute) as StructDrawerAttribute;
            }
            if (attr == null)
            {
                attr = data.Attributes.FirstOrDefault(e => e is StructDrawerAttribute) as StructDrawerAttribute;
            }
            if (attr == null)
            {
                attr = new StructDrawerAttribute();
            }

            switch (data.Parent != null ? attr.ItemType : StructDrawerAttribute.ItemTypes.None)
            {
            case StructDrawerAttribute.ItemTypes.FadeGroup:
                //EditorGUILayout.GetControlRect(false, 10, GUILayout.Width(8));
                EditorGUILayout.BeginVertical();
                //data.Property.isExpanded = EditorGUILayout.Foldout(data.Property.isExpanded, new GUIContent(data.Property.displayName));

                if (EditorGUILayout.DropdownButton(new GUIContent(data.Property.displayName), FocusType.Passive,
                                                   data.Property.isExpanded ? Style.FoldoutExpanded : Style.Foldout))
                {
                    data.Property.isExpanded = !data.Property.isExpanded;
                }

                if (data.Property.isExpanded)
                {
                    int lastIndent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel = 1;
                    DrawProperies(data);
                    EditorGUI.indentLevel = lastIndent;
                }

                EditorGUILayout.EndVertical();
                break;

            case StructDrawerAttribute.ItemTypes.Box:
                EditorGUILayout.BeginVertical(Style.ListItemBox);
                DrawProperies(data);
                EditorGUILayout.EndVertical();
                break;

            case StructDrawerAttribute.ItemTypes.HorizontalGroup:
                EditorGUILayout.BeginHorizontal();
                DrawProperies(data);
                EditorGUILayout.EndHorizontal();
                break;

            default:
                EditorGUILayout.BeginVertical();
                DrawProperies(data);
                EditorGUILayout.EndVertical();
                break;
            }
        }
Exemplo n.º 9
0
        public void DrawProperies(PropertyData data)
        {
            var buttons = Utilities.FindByAttribute <ButtonAttribute, MethodInfo>(data.Value);

            DrawMethodButtons(data, buttons, ButtonAttribute.AlignTypes.Top);

            Dictionary <OrderItem, string> itemList = new Dictionary <OrderItem, string>();
            OrderItem items = new OrderItem("", 0);
            Dictionary <string, OrderItem> attrList = new Dictionary <string, OrderItem>();

            var iterator = data.Property.Copy();
            int index    = 0;

            for (bool enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false)
            {
                if (string.IsNullOrEmpty(data.Property.propertyPath) || iterator.propertyPath.IndexOf(data.Property.propertyPath, StringComparison.Ordinal) == 0)
                {
                    PropertyData itemData = new PropertyData(iterator.Copy(), data);
                    if ("m_Script" == iterator.propertyPath)
                    {
                        EditorGUI.BeginDisabledGroup(true);
                        Editor.Property.Draw(itemData);
                        EditorGUI.EndDisabledGroup();
                    }
                    else
                    {
                        string path = "";
                        foreach (var attribute in itemData.Attributes.Select(e => e as GroupAttribute))
                        {
                            if (attribute != null)
                            {
                                if (!attrList.ContainsKey(attribute.Name))
                                {
                                    attrList.Add(attribute.Name, new OrderItem(attribute, index));
                                }
                                path = path.Length < attribute.Name.Length ? attribute.Name : path;
                            }
                        }

                        itemList.Add(new OrderItem(itemData, index), path);
                        //var groupAttr = itemData.Attributes.FirstOrDefault(e => e is GroupAttribute) as GroupAttribute;
                        //items.Add(groupAttr != null ? groupAttr.Name, , new OrderItem(itemData, index));
                        //AddItem(items, new OrderItem(itemData, index));
                        index++;
                    }
                }
            }

            foreach (var pair in attrList)
            {
                items.Add(pair.Value, pair.Key);
            }

            foreach (var pair in itemList)
            {
                items.Add(pair.Key, pair.Value);
            }

            items.Sort();
            items.Draw(e => Editor.Property.Draw(e.Data));

            DrawMethodButtons(data, buttons, ButtonAttribute.AlignTypes.Bottom);
        }