Пример #1
0
        private void CreateListData(InspectableProperty property)
        {
            var root = property.GetRootPath();
            // Try to find the grand parent in ReorderableListData
            var data = listIndex.Find(listData => listData.Parent.Equals(root));

            if (data == null)
            {
                data = new ReorderableListData(root);
                listIndex.Add(data);
            }

            data.AddProperty(property);
            if (property.HasAttribute <ReorderableAttribute>())
            {
                var reorderableAttr = property.GetAttributes <ReorderableAttribute>()[0] as ReorderableAttribute;
                if (reorderableAttr != null)
                {
                    HandleReorderableOptions(reorderableAttr, property, data);
                }
            }
            if (property.HasAttribute <BackgroundColorAttribute>())
            {
                var bgColorAttr = property.GetAttributes <BackgroundColorAttribute>()[0] as BackgroundColorAttribute;
                if (bgColorAttr != null)
                {
                    HandleBackgroundColorOptions(bgColorAttr, property, data);
                }
            }
        }
        public void AddProperty(InspectableProperty property)
        {
            // Check if this property actually belongs to the same direct child
            if (!property.GetRootPath().Equals(Parent))
            {
                return;
            }

            if (extendListIndex.ContainsKey(property.PropertyPath))
            {
                return;
            }

            InspectableReorderableList propList = new InspectableReorderableList(
                property.InspectableObject.SerializedObject, property,
                draggable: true, displayHeader: false,
                displayAddButton: true, displayRemoveButton: true)
            {
                headerHeight = 5
            };

            propList.drawElementBackgroundCallback = delegate(Rect position, int index, bool active, bool focused)
            {
                if (DrawBackgroundCallback != null)
                {
                    Rect backgroundRect = new Rect(position);
                    if (index <= 0)
                    {
                        backgroundRect.yMin -= 8;
                    }
                    if (index >= propList.count - 1)
                    {
                        backgroundRect.yMax += 3;
                    }
                    EditorGUI.DrawRect(backgroundRect, DrawBackgroundCallback(active, focused));
                }
                else
                {
                    propList.drawElementBackgroundCallback = null;
                }
            };

            propList.drawElementCallback = delegate(Rect position, int index, bool active, bool focused)
            {
                var iterProp    = property.GetArrayElementAtIndex(index);
                var displayName = new GUIContent(iterProp.DisplayName);
                if (ElementNameCallback != null)
                {
                    var elementName = ElementNameCallback(index);
                    displayName = elementName == null ? GUIContent.none : new GUIContent(elementName);
                }

                EasyGUI.TryDrawInspectableObject(position, iterProp, displayName, IsDrawObjectReference);
            };

            propList.elementHeightCallback = index => ElementHeightCallback(property, index);

            extendListIndex.Add(property.PropertyPath, propList);
        }