private float ElementHeightCallback(InspectableProperty property, int index)
        {
            var height   = 3f;
            var iterProp = property.GetArrayElementAtIndex(index);

            if (iterProp.IsExpanded || !ElementHeights.ContainsKey(index))
            {
                var displayName = new GUIContent(iterProp.DisplayName);
                if (ElementNameCallback != null)
                {
                    var elementName = ElementNameCallback(index);
                    displayName = elementName == null ? GUIContent.none : new GUIContent(elementName);
                }

                height += EasyGUI.GetInspectableObjectHeight(iterProp, displayName, IsDrawObjectReference);
                if (!iterProp.IsExpanded)
                {
                    ElementHeights.Add(index, height);
                }
            }
            else
            {
                height = ElementHeights[index];
            }

            return(height);
        }
        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);
        }
Пример #3
0
            public bool MoveNext()
            {
                uint num = (uint)position;

                position = -1;
                switch (num)
                {
                case 0:
                    if (!target.IsArray)
                    {
                        end = target.GetEndProperty();
                        if (target.NextVisible(true) && !InspectableProperty.EqualContents(target, end))
                        {
                            current = target;
                            if (!disposing)
                            {
                                position = 2;
                            }
                            return(true);
                        }
                        position = -1;
                        return(false);
                    }
                    index = 0;
                    break;

                case 1:
                    index++;
                    break;

                case 2:
                    if (target.NextVisible(true) && !InspectableProperty.EqualContents(target, end))
                    {
                        current = target;
                        if (!disposing)
                        {
                            position = 2;
                        }
                        return(true);
                    }
                    position = -1;
                    return(false);

                default:
                    return(false);
                }
                if (index >= target.ArraySize)
                {
                    position = -1;
                    return(false);
                }
                current = target.GetArrayElementAtIndex(index);
                if (!disposing)
                {
                    position = 1;
                }
                return(true);
            }
        public float GetPropertyHeight(InspectableProperty property)
        {
            var height = EasyGUI.GetPropertyHeight(property, new GUIContent(property.DisplayName), false);

            if (property.IsExpanded)
            {
                for (int i = 0; i < property.ArraySize; i++)
                {
                    var iterProp    = property.GetArrayElementAtIndex(i);
                    var displayName = new GUIContent(iterProp.DisplayName);
                    if (ElementNameCallback != null)
                    {
                        iterProp.DisplayName = ElementNameCallback(i);
                        displayName          = iterProp.DisplayName == null ? GUIContent.none : new GUIContent(iterProp.DisplayName);
                    }
                    height += EasyGUI.GetInspectableObjectHeight(iterProp, displayName, IsDrawObjectReference);
                }
                height += 3 * EditorGUIUtility.singleLineHeight;
            }
            return(height);
        }
Пример #5
0
        private void DoListElements(Rect listRect)
        {
            // How many elements? If none, make space for showing default line that shows no elements are present
            int arraySize = count;

            // draw the background in repaint
            if (showDefaultBackground && Event.current.type == EventType.Repaint)
            {
                s_Defaults.boxBackground.Draw(listRect, false, false, false, false);
            }

            // resize to the area that we want to draw our elements into
            listRect.yMin += 2;
            listRect.yMax -= 5;


            // create the rect for individual elements in the list
            Rect elementRect = listRect;

            elementRect.height = elementHeight;

            // the content rect is what we will actually draw into -- it doesn't include the drag handle or padding
            Rect elementContentRect = elementRect;


            if (((m_Elements != null && m_Elements.IsArray == true) || m_ElementList != null) && arraySize > 0)
            {
                // If there are elements, we need to draw them -- we will do this differently depending on if we are dragging or not
                if (IsDragging() && Event.current.type == EventType.Repaint)
                {
                    // we are dragging, so we need to build the new list of target indices
                    int targetIndex = CalculateRowIndex();
                    m_NonDragTargetIndices.Clear();
                    for (int i = 0; i < arraySize; i++)
                    {
                        if (i != m_ActiveElement)
                        {
                            m_NonDragTargetIndices.Add(i);
                        }
                    }
                    m_NonDragTargetIndices.Insert(targetIndex, -1);

                    // now draw each element in the list (excluding the active element)
                    bool targetSeen = false;
                    for (int i = 0; i < m_NonDragTargetIndices.Count; i++)
                    {
                        if (m_NonDragTargetIndices[i] != -1)
                        {
                            elementRect.height = GetElementHeight(i);
                            // update the position of the rect (based on element position and accounting for sliding)
                            if (elementHeightCallback == null)
                            {
                                elementRect.y = listRect.y + GetElementYOffset(i, m_ActiveElement);
                            }
                            else
                            {
                                elementRect.y = listRect.y + GetElementYOffset(m_NonDragTargetIndices[i], m_ActiveElement);
                                if (targetSeen)
                                {
                                    elementRect.y += elementHeightCallback(m_ActiveElement);
                                }
                            }
                            elementRect = m_SlideGroup.GetRect(m_NonDragTargetIndices[i], elementRect);

                            // actually draw the element
                            if (drawElementBackgroundCallback == null)
                            {
                                s_Defaults.DrawElementBackground(elementRect, i, false, false, m_Draggable);
                            }
                            else
                            {
                                drawElementBackgroundCallback(elementRect, i, false, false);
                            }

                            s_Defaults.DrawElementDraggingHandle(elementRect, i, false, false, m_Draggable);

                            elementContentRect = GetContentRect(elementRect);
                            if (drawElementCallback == null)
                            {
                                if (m_Elements != null)
                                {
                                    s_Defaults.DrawElement(elementContentRect, m_Elements.GetArrayElementAtIndex(m_NonDragTargetIndices[i]), null, false, false, m_Draggable);
                                }
                                else
                                {
                                    s_Defaults.DrawElement(elementContentRect, null, m_ElementList[m_NonDragTargetIndices[i]], false, false, m_Draggable);
                                }
                            }
                            else
                            {
                                drawElementCallback(elementContentRect, m_NonDragTargetIndices[i], false, false);
                            }
                        }
                        else
                        {
                            targetSeen = true;
                        }
                    }

                    // finally get the position of the active element
                    elementRect.y = m_DraggedY - m_DragOffset + listRect.y;

                    // actually draw the element
                    if (drawElementBackgroundCallback == null)
                    {
                        s_Defaults.DrawElementBackground(elementRect, m_ActiveElement, true, true, m_Draggable);
                    }
                    else
                    {
                        drawElementBackgroundCallback(elementRect, m_ActiveElement, true, true);
                    }

                    s_Defaults.DrawElementDraggingHandle(elementRect, m_ActiveElement, true, true, m_Draggable);


                    elementContentRect = GetContentRect(elementRect);

                    // draw the active element
                    if (drawElementCallback == null)
                    {
                        if (m_Elements != null)
                        {
                            s_Defaults.DrawElement(elementContentRect, m_Elements.GetArrayElementAtIndex(m_ActiveElement), null, true, true, m_Draggable);
                        }
                        else
                        {
                            s_Defaults.DrawElement(elementContentRect, null, m_ElementList[m_ActiveElement], true, true, m_Draggable);
                        }
                    }
                    else
                    {
                        drawElementCallback(elementContentRect, m_ActiveElement, true, true);
                    }
                }
                else
                {
                    // if we aren't dragging, we just draw all of the elements in order
                    for (int i = 0; i < arraySize; i++)
                    {
                        bool activeElement  = (i == m_ActiveElement);
                        bool focusedElement = (i == m_ActiveElement && HasKeyboardControl());

                        // update the position of the element
                        elementRect.height = GetElementHeight(i);
                        elementRect.y      = listRect.y + GetElementYOffset(i);

                        // draw the background
                        if (drawElementBackgroundCallback == null)
                        {
                            s_Defaults.DrawElementBackground(elementRect, i, activeElement, focusedElement, m_Draggable);
                        }
                        else
                        {
                            drawElementBackgroundCallback(elementRect, i, activeElement, focusedElement);
                        }
                        s_Defaults.DrawElementDraggingHandle(elementRect, i, activeElement, focusedElement, m_Draggable);


                        elementContentRect = GetContentRect(elementRect);

                        // do the callback for the element
                        if (drawElementCallback == null)
                        {
                            if (m_Elements != null)
                            {
                                s_Defaults.DrawElement(elementContentRect, m_Elements.GetArrayElementAtIndex(i), null, activeElement, focusedElement, m_Draggable);
                            }
                            else
                            {
                                s_Defaults.DrawElement(elementContentRect, null, m_ElementList[i], activeElement, focusedElement, m_Draggable);
                            }
                        }
                        else
                        {
                            drawElementCallback(elementContentRect, i, activeElement, focusedElement);
                        }
                    }
                }

                // handle the interaction
                DoDraggingAndSelection(listRect);
            }
            else
            {
                // there was no content, so we will draw an empty element
                elementRect.y = listRect.y;
                // draw the background
                if (drawElementBackgroundCallback == null)
                {
                    s_Defaults.DrawElementBackground(elementRect, -1, false, false, false);
                }
                else
                {
                    drawElementBackgroundCallback(elementRect, -1, false, false);
                }
                s_Defaults.DrawElementDraggingHandle(elementRect, -1, false, false, false);

                elementContentRect       = elementRect;
                elementContentRect.xMin += Defaults.padding;
                elementContentRect.xMax -= Defaults.padding;
                if (drawNoneElementCallback == null)
                {
                    s_Defaults.DrawNoneElement(elementContentRect, m_Draggable);
                }
                else
                {
                    drawNoneElementCallback(elementContentRect);
                }
            }
        }