Esempio n. 1
0
        public void AddProperty(SerializedProperty property)
        {
            // Check if this property actually belongs to the same direct child
            if (!property.GetRootPath().Equals(Parent))
            {
                return;
            }

            if (listIndex.ContainsKey(property.propertyPath))
            {
                return;
            }

            var propList = new ReorderableList(
                property.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);
                }

                position.xMin += 5;
                if (EasyGUI.TryDrawInspectableObject(position, iterProp, IsDrawObjectReference, ElementHeaderCallback, ElementFooterCallback))
                {
                }
                else
                {
                    EasyGUI.TryDrawPropertyField(position, iterProp, displayName, IsDrawObjectReference);
                }
            };

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

            listIndex.Add(property.propertyPath, propList);
        }