Пример #1
0
    public static void MakeList(ref Rect drawRect, ref float height, SerializedProperty listProp,
                                bool showOrder = false, bool showSize = true)
    {
        EditorGUI.indentLevel++;
        var listSize  = listProp.arraySize;
        var iconWidth = 14;
        var iconGap   = 3f;

        if (showSize)
        {
            if (showOrder)
            {
                var temp        = INDENT_WIDTH + GAP_WIDTH + iconGap;
                var elementRect = new Rect(drawRect.x, drawRect.y, drawRect.width - iconWidth + 2, drawRect.height);
                var iconRect    = new Rect(drawRect.width - iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
                if (XChartsSettings.editorBlockEnable)
                {
                    iconRect.x += BLOCK_WIDTH;
                }
                var oldColor = GUI.contentColor;
                GUI.contentColor = Color.black;
                if (GUI.Button(iconRect, Styles.iconAdd, Styles.invisibleButton))
                {
                    if (listProp.displayName.Equals("Series"))
                    {
                        AddSerieEditor.chart = listProp.serializedObject.targetObject as BaseChart;
                        AddSerieEditor.ShowWindow();
                    }
                    else
                    {
                        listProp.arraySize++;
                    }
                }
                GUI.contentColor = oldColor;
                listSize         = listProp.arraySize;
                listSize         = EditorGUI.IntField(elementRect, "Size", listSize);
            }
            else
            {
                listSize = EditorGUI.IntField(drawRect, "Size", listSize);
            }
            if (listSize < 0)
            {
                listSize = 0;
            }
            drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
            height     += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;

            if (listSize != listProp.arraySize)
            {
                while (listSize > listProp.arraySize)
                {
                    listProp.arraySize++;
                }
                while (listSize < listProp.arraySize)
                {
                    listProp.arraySize--;
                }
            }
        }
        if (listSize > 30 && !XChartsSettings.editorShowAllListData)
        {
            SerializedProperty element;
            int num = listSize > 10 ? 10 : listSize;
            for (int i = 0; i < num; i++)
            {
                element = listProp.GetArrayElementAtIndex(i);
                EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + i));
                drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
                height     += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
            }
            if (num >= 10)
            {
                EditorGUI.LabelField(drawRect, "...");
                drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                height     += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                element     = listProp.GetArrayElementAtIndex(listSize - 1);
                EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + (listSize - 1)));
                drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
                height     += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
            }
        }
        else
        {
            for (int i = 0; i < listProp.arraySize; i++)
            {
                SerializedProperty element = listProp.GetArrayElementAtIndex(i);
                if (showOrder)
                {
                    var temp        = INDENT_WIDTH + GAP_WIDTH + iconGap;
                    var isSerie     = "Serie".Equals(element.type);
                    var elementRect = isSerie
                        ? new Rect(drawRect.x, drawRect.y, drawRect.width + INDENT_WIDTH - 2 * iconGap, drawRect.height)
                        : new Rect(drawRect.x, drawRect.y, drawRect.width - 3 * iconWidth, drawRect.height);
                    EditorGUI.PropertyField(elementRect, element, new GUIContent("Element " + i));
                    var iconRect = new Rect(drawRect.width - 3 * iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
                    if (XChartsSettings.editorBlockEnable)
                    {
                        iconRect.x += BLOCK_WIDTH;
                    }
                    var oldColor = GUI.contentColor;
                    GUI.contentColor = Color.black;
                    if (GUI.Button(iconRect, Styles.iconUp, Styles.invisibleButton))
                    {
                        if (i > 0)
                        {
                            listProp.MoveArrayElement(i, i - 1);
                        }
                    }
                    iconRect = new Rect(drawRect.width - 2 * iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
                    if (XChartsSettings.editorBlockEnable)
                    {
                        iconRect.x += BLOCK_WIDTH;
                    }
                    if (GUI.Button(iconRect, Styles.iconDown, Styles.invisibleButton))
                    {
                        if (i < listProp.arraySize - 1)
                        {
                            listProp.MoveArrayElement(i, i + 1);
                        }
                    }
                    iconRect = new Rect(drawRect.width - iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
                    if (XChartsSettings.editorBlockEnable)
                    {
                        iconRect.x += BLOCK_WIDTH;
                    }
                    if (GUI.Button(iconRect, Styles.iconRemove, Styles.invisibleButton))
                    {
                        if (i < listProp.arraySize && i >= 0)
                        {
                            listProp.DeleteArrayElementAtIndex(i);
                        }
                    }
                    else
                    {
                        drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
                        height     += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
                    }
                    GUI.contentColor = oldColor;
                }
                else
                {
                    EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + i));
                    drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
                    height     += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
                }
            }
        }
        EditorGUI.indentLevel--;
    }
Пример #2
0
    public static void MakeList(ref Rect drawRect, ref float height, ref int listSize, SerializedProperty listProp, bool showOrder = false, bool showSize = true)
    {
        EditorGUI.indentLevel++;
        listSize = listProp.arraySize;
        if (showSize)
        {
            if (showOrder)
            {
                var nameWid     = 18;
                var temp        = INDENT_WIDTH + GAP_WIDTH;
                var elementRect = new Rect(drawRect.x, drawRect.y, drawRect.width - nameWid - 1, drawRect.height);
                var iconRect    = new Rect(drawRect.width - nameWid + temp, drawRect.y, nameWid, drawRect.height);
                if (XChartsSettings.editorBlockEnable)
                {
                    iconRect.x += BLOCK_WIDTH;
                }
                if (GUI.Button(iconRect, new GUIContent("+", "add")))
                {
                    if (listProp.displayName.Equals("Series"))
                    {
                        AddSerieEditor.chart = listProp.serializedObject.targetObject as BaseChart;
                        AddSerieEditor.ShowWindow();
                    }
                    else
                    {
                        listProp.arraySize++;
                    }
                }
                listSize = listProp.arraySize;
                listSize = EditorGUI.IntField(elementRect, "Size", listSize);
            }
            else
            {
                listSize = EditorGUI.IntField(drawRect, "Size", listSize);
            }
            if (listSize < 0)
            {
                listSize = 0;
            }
            drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
            height     += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;

            if (listSize != listProp.arraySize)
            {
                while (listSize > listProp.arraySize)
                {
                    listProp.arraySize++;
                }
                while (listSize < listProp.arraySize)
                {
                    listProp.arraySize--;
                }
            }
        }
        if (listSize > 30)
        {
            SerializedProperty element;
            int num = listSize > 10 ? 10 : listSize;
            for (int i = 0; i < num; i++)
            {
                element = listProp.GetArrayElementAtIndex(i);
                EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + i));
                drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
                height     += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
            }
            if (num >= 10)
            {
                EditorGUI.LabelField(drawRect, "...");
                drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                height     += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                element     = listProp.GetArrayElementAtIndex(listSize - 1);
                EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + (listSize - 1)));
                drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
                height     += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
            }
        }
        else
        {
            for (int i = 0; i < listProp.arraySize; i++)
            {
                SerializedProperty element = listProp.GetArrayElementAtIndex(i);
                if (showOrder)
                {
                    var nameWid     = 18;
                    var temp        = INDENT_WIDTH + GAP_WIDTH;
                    var isSerie     = "Serie".Equals(element.type);
                    var elementRect = isSerie ? drawRect : new Rect(drawRect.x, drawRect.y, drawRect.width - 2 * nameWid, drawRect.height);
                    EditorGUI.PropertyField(elementRect, element, new GUIContent("Element " + i));
                    var iconRect = new Rect(drawRect.width - 3 * nameWid + temp, drawRect.y, nameWid, drawRect.height);
                    if (XChartsSettings.editorBlockEnable)
                    {
                        iconRect.x += BLOCK_WIDTH;
                    }
                    if (GUI.Button(iconRect, new GUIContent("↑", "up")))
                    {
                        if (i > 0)
                        {
                            listProp.MoveArrayElement(i, i - 1);
                        }
                    }
                    iconRect = new Rect(drawRect.width - 2 * nameWid + temp, drawRect.y, nameWid, drawRect.height);
                    if (XChartsSettings.editorBlockEnable)
                    {
                        iconRect.x += BLOCK_WIDTH;
                    }
                    if (GUI.Button(iconRect, new GUIContent("↓", "down")))
                    {
                        if (i < listProp.arraySize - 1)
                        {
                            listProp.MoveArrayElement(i, i + 1);
                        }
                    }
                    iconRect = new Rect(drawRect.width - nameWid + temp, drawRect.y, nameWid, drawRect.height);
                    if (XChartsSettings.editorBlockEnable)
                    {
                        iconRect.x += BLOCK_WIDTH;
                    }
                    if (GUI.Button(iconRect, new GUIContent("-", "delete")))
                    {
                        if (i < listProp.arraySize && i >= 0)
                        {
                            listProp.DeleteArrayElementAtIndex(i);
                        }
                    }
                    else
                    {
                        drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
                        height     += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
                    }
                }
                else
                {
                    EditorGUI.PropertyField(drawRect, element, new GUIContent("Element " + i));
                    drawRect.y += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
                    height     += EditorGUI.GetPropertyHeight(element) + EditorGUIUtility.standardVerticalSpacing;
                }
            }
        }
        EditorGUI.indentLevel--;
    }