Exemplo n.º 1
0
        private void HandleArray(SerializedProperty prop)
        {
            var attrs                   = UTUtils.GetPropertyAttributes(prop);
            var modifierAttrs           = UTUtils.GetPropertyAttributes <Attribute>(prop);
            var isGroup                 = attrs.Where(a => a is ListViewAttribute).ToArray().Length > 0;
            var groupAttribute          = attrs.Select(a => a as ListViewAttribute).ToArray();
            var onValueChangedAttribute = UTUtils.GetPropertyAttribute <OnValueChangedAttribute>(prop);

            // hideIf attribute
            var hideIfAttribute = modifierAttrs.OfType <HideIfAttribute>().ToArray();
            var isHidden        = hideIfAttribute.Length > 0 && UTUtils.GetVisibleThroughAttribute(prop, hideIfAttribute[0].methodName, false);

            // handling for regular arrays, make nicer down the line
            if (!isGroup)
            {
                if (isHidden)
                {
                    return;
                }
                RenderArray(prop, onValueChangedAttribute?.methodName);
                if (droppedObjects)
                {
                    return;
                }
                RenderHelpBox(prop);
                return;
            }

            var groupName = groupAttribute[0].name;
            var items     = cT.GetFields().Where(f =>
                                                 f.GetAttribute <ListViewAttribute>() != null && f.GetAttribute <ListViewAttribute>().name == groupName)
                            .ToList();

            // fast exit on 1 element with list view
            if (items.Count < 2)
            {
                if (isHidden)
                {
                    return;
                }
                RenderArray(prop, onValueChangedAttribute?.methodName);
                if (droppedObjects)
                {
                    return;
                }
                RenderHelpBox(prop);
                return;
            }

            var index = items.FindIndex(a => a.Name == prop.name);

            if (index > 0)
            {
                return;
            }

            var sectionHeaderAttribute = UTUtils.GetPropertyAttribute <SectionHeaderAttribute>(prop);

            if (sectionHeaderAttribute != null)
            {
                UTStyles.RenderSectionHeader(sectionHeaderAttribute.text);
            }

            if (isHidden)
            {
                return;
            }

            var otherProp           = serializedObject.FindProperty(items[1].Name);
            var leftPopupAttribute  = UTUtils.GetPropertyAttribute <PopupAttribute>(prop);
            var rightPopupAttribute = UTUtils.GetPropertyAttribute <PopupAttribute>(otherProp);

            if (rightPopupAttribute != null || leftPopupAttribute != null)
            {
                RenderStackedArray(groupAttribute[0].name, prop, otherProp, leftPopupAttribute, rightPopupAttribute, groupAttribute[0].addMethodName,
                                   groupAttribute[0].addButtonText, onValueChangedAttribute?.methodName);
                if (droppedObjects)
                {
                    return;
                }
                RenderHelpBox(prop);
                return;
            }

            RenderStackedArray(groupAttribute[0].name, prop, otherProp, groupAttribute[0].addMethodName,
                               groupAttribute[0].addButtonText, onValueChangedAttribute?.methodName);
            if (droppedObjects)
            {
                return;
            }
            RenderHelpBox(prop);
        }