Ejemplo n.º 1
0
        public bool MoveNext()
        {
            uint num = (uint)position;

            position = -1;
            switch (num)
            {
            case 0:
                if (!target.IsArray)
                {
                    end = target.GetEndProperty();
                    if (target.NextVisible(true) && !RuntimeSerializedProperty.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) && !RuntimeSerializedProperty.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 void AddProperty(RuntimeSerializedProperty property)
        {
            // Check if this property actually belongs to the same direct child
            if (!property.GetRootPath().Equals(Parent))
            {
                return;
            }

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

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

            propList.drawElementBackgroundCallback = (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 = (Rect position, int index, bool active, bool focused) =>
            {
                var iterProp    = property.GetArrayElementAtIndex(index);
                var elementName = iterProp.DisplayName;
                if (ElementNameCallback != null)
                {
                    elementName = ElementNameCallback(index);
                }
                RuntimeEasyGUI.PropertyField(position, iterProp, new GUIContent(elementName), ElementAttributes);
            };

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

            runtimeReorderableListDict.Add(property.PropertyPath, propList);
        }
        private float ElementHeightCallback(RuntimeSerializedProperty property, int index)
        {
            var height      = 3f;
            var iterProp    = property.GetArrayElementAtIndex(index);
            var elementName = iterProp.DisplayName;

            if (ElementNameCallback != null)
            {
                elementName = ElementNameCallback(index);
            }
            height += RuntimeEasyGUI.GetPropertyHeight(iterProp, new GUIContent(elementName), ElementAttributes);

            return(height);
        }
        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);
                }
            }
        }