示例#1
0
 // PRIVATE
 private void drawComponentLabel(Rect rect, QHierarchyComponentEnum type, bool withBackground = false)
 {
     if (withBackground)
     {
         EditorGUI.DrawRect(new Rect(rect.x, rect.y - 2, rect.width, 20), backgroundColor);
     }
     GUI.DrawTexture(new Rect(rect.x, rect.y - 2, 20, 20), dragButton);
     GUI.Label(new Rect(rect.x + 27, rect.y, rect.width - 20, 16), getTextWithSpaces(type.ToString()));
 }
        // PRIVATE
        private void drawComponentLabel(Rect rect, QHierarchyComponentEnum type, bool withBackground = false)
        {
            if (withBackground)
            {
                EditorGUI.DrawRect(new Rect(rect.x, rect.y - 2, rect.width, 20), backgroundColor);
            }
            GUI.DrawTexture(new Rect(rect.x, rect.y - 2, 20, 20), dragButton);
            Rect labelRect = new Rect(rect.x + 31, rect.y, rect.width - 20, 16);

            labelRect.y -= (EditorGUIUtility.singleLineHeight - labelRect.height) * 0.5f;
            EditorGUI.LabelField(labelRect, getTextWithSpaces(type.ToString()));
        }
示例#3
0
        // PUBLIC
        public void draw(Rect rect, string[] componentIds)
        {
            Event currentEvent = Event.current;

            int currentMouseIndex = Mathf.Clamp(Mathf.RoundToInt((currentEvent.mousePosition.y - dragOffset - rect.y) / 18), 0, componentIds.Length - 1);

            if (dragAndDrop && currentEvent.type == EventType.MouseUp)
            {
                dragAndDrop = false;
                window.Repaint();

                if (currentMouseIndex != originalDragIndex)
                {
                    string newIconOrder = "";
                    for (int j = 0; j < componentIds.Length; j++)
                    {
                        if (j == currentMouseIndex)
                        {
                            if (j > originalDragIndex)
                            {
                                newIconOrder += componentIds[j] + ";";
                                newIconOrder += componentIds[originalDragIndex] + ";";
                            }
                            else
                            {
                                newIconOrder += componentIds[originalDragIndex] + ";";
                                newIconOrder += componentIds[j] + ";";
                            }
                        }
                        else if (j != originalDragIndex)
                        {
                            newIconOrder += componentIds[j] + ";";
                        }
                    }
                    newIconOrder = newIconOrder.TrimEnd(';');
                    QSettings.getInstance().set(QSetting.ComponentsOrder, newIconOrder);
                    componentIds = newIconOrder.Split(';');
                }
            }
            else if (dragAndDrop && currentEvent.type == EventType.MouseDrag)
            {
                window.Repaint();
            }

            for (int i = 0; i < componentIds.Length; i++)
            {
                QHierarchyComponentEnum type = (QHierarchyComponentEnum)int.Parse(componentIds[i]);

                Rect curRect = new Rect(rect.x, rect.y + 18 * i, rect.width, 16);

                if (!dragAndDrop && currentEvent.type == EventType.MouseDown && curRect.Contains(currentEvent.mousePosition))
                {
                    dragAndDrop       = true;
                    originalDragIndex = i;
                    dragOffset        = currentEvent.mousePosition.y - curRect.y;
                    Event.current.Use();
                }

                if (dragAndDrop)
                {
                    if (originalDragIndex != i)
                    {
                        if (i < originalDragIndex && currentMouseIndex <= i)
                        {
                            curRect.y += 18;
                        }
                        else if (i > originalDragIndex && currentMouseIndex >= i)
                        {
                            curRect.y -= 18;
                        }

                        drawComponentLabel(curRect, type);
                    }
                }
                else
                {
                    drawComponentLabel(curRect, type);
                }
            }

            if (dragAndDrop)
            {
                float curY = currentEvent.mousePosition.y - dragOffset;
                curY = Mathf.Clamp(curY, rect.y, rect.y + rect.height - 16);
                drawComponentLabel(new Rect(rect.x, curY, rect.width, rect.height), (QHierarchyComponentEnum)int.Parse(componentIds[originalDragIndex]), true);
            }
        }
        // ORDER
        private void drawOrderSettings()
        {
            indentLevel += 8;

            string componentOrder = QSettings.getInstance().get <string>(QSetting.ComponentOrder);

            string[] componentIds = componentOrder.Split(';');

            for (int i = 0; i < componentIds.Length; i++)
            {
                QHierarchyComponentEnum type = (QHierarchyComponentEnum)int.Parse(componentIds[i]);

                Rect rect = getControlRect(14, 17);

                if (i > 0)
                {
                    if (GUI.Button(rect, orderUp, GUIStyle.none))
                    {
                        string newIconOrder = "";
                        for (int j = 0; j < componentIds.Length; j++)
                        {
                            if (j == i - 1)
                            {
                                newIconOrder += componentIds[i] + ";";
                            }
                            else if (j == i)
                            {
                                newIconOrder += componentIds[i - 1] + ";";
                            }
                            else
                            {
                                newIconOrder += componentIds[j] + ";";
                            }
                        }
                        newIconOrder = newIconOrder.TrimEnd(';');
                        QSettings.getInstance().set(QSetting.ComponentOrder, newIconOrder);
                    }
                }

                rect.x += 17;

                if (i < componentIds.Length - 1)
                {
                    if (GUI.Button(rect, orderDown, GUIStyle.none))
                    {
                        string newIconOrder = "";
                        for (int j = 0; j < componentIds.Length; j++)
                        {
                            if (j == i)
                            {
                                newIconOrder += componentIds[i + 1] + ";";
                            }
                            else if (j == i + 1)
                            {
                                newIconOrder += componentIds[i] + ";";
                            }
                            else
                            {
                                newIconOrder += componentIds[j] + ";";
                            }
                        }
                        newIconOrder = newIconOrder.TrimEnd(';');
                        QSettings.getInstance().set(QSetting.ComponentOrder, newIconOrder);
                    }
                }

                rect.x     += 19;
                rect.y     -= 1;
                rect.width  = 200;
                rect.height = 22;
                GUI.Label(rect, getTextWithSpaces(type.ToString()));
            }

            indentLevel -= 8;
        }