示例#1
0
        private bool DrawRowHeader()
        {
            bool changed = false;

            EditorGUILayout.BeginVertical();
            changed |= EditorGUIUtil.ObjectField <UITableCell>(ref table.defaultPrefab, true, W_Option, H_Option);
            EditorGUILayout.LabelField("Align", EditorStyles.boldLabel, H_Option);
            EditorGUILayout.LabelField("Size", EditorStyles.boldLabel, H_Option);
            EditorGUILayout.LabelField("Index", EditorStyles.boldLabel, H_Option);
            int row = table.isVertical? table.GetMaxPerLine(): table.rowCount;

            table.InitArray();
            for (int r = 0; r < row; r++)
            {
                EditorGUILayout.BeginHorizontal();
                changed |= EditorGUIUtil.ObjectField <UITableCell>(ref table.rowPrefab[r], true, GUILayout.Width(WIDTH - 20), H_Option);
                changed |= EditorGUIUtil.Popup <UITableLayout.VAlign>(ref table.valigns[r], EnumUtil.Values <UITableLayout.VAlign>(), GUILayout.Width(40), H_Option);
                changed |= EditorGUIUtil.IntField(null, ref table.rowHeight[r], GUILayout.Width(WIDTH - 30), H_Option);
                EditorGUILayout.LabelField((r + 1).ToString(), EditorStyles.boldLabel, GUILayout.Width(20), H_Option);
                EditorGUILayout.EndHorizontal();
            }
            if (!IsHorizontal())
            {
                EditorGUILayout.LabelField("", W_Option);
                EditorGUILayout.LabelField("", W_Option);
                EditorGUILayout.LabelField("", W_Option);
            }
            EditorGUILayout.EndVertical();
            if (changed)
            {
                table.InitArray();
            }
            return(changed);
        }
示例#2
0
        private bool DrawTableStructure()
        {
            bool changed = false;

            if (NGUIEditorTools.DrawHeader("Table Structure"))
            {
                NGUIEditorTools.BeginContents();
                EditorGUILayout.HelpBox("Modifying structure values may occur unintented result", MessageType.Warning);
                changed = EditorGUIUtil.PopupEnum <UITableLayout.Arrangement>("Orientation", ref grid.arrangement, GUILayout.ExpandWidth(false));
                string rowCol = grid.isHorizontal? "Column Size": "Row Size";
                if (EditorGUIUtil.IntField(rowCol, ref grid.maxPerLine, GUILayout.ExpandWidth(false)))
                {
                    if (grid.maxPerLine <= 0)
                    {
                        grid.maxPerLine = 1;
                    }
                    changed = true;
                }
                changed |= EditorGUIUtil.IntField("Row Header", ref grid.rowHeader, GUILayout.ExpandWidth(false));
                changed |= EditorGUIUtil.IntField("Column Header", ref grid.columnHeader, GUILayout.ExpandWidth(false));
                changed |= EditorGUIUtil.Toggle("Reuse Cell", ref grid.reuseCell, GUILayout.ExpandWidth(false));
                NGUIEditorTools.EndContents();
            }
            if (changed)
            {
                grid.InitArray();
            }
            return(changed);
        }
示例#3
0
        protected override bool OnInspectorGUI(RenderQueueElement info, int i)
        {
            float width   = GetWidth();
            bool  changed = false;

            changed |= EditorGUIUtil.TextField(null, ref info.name, GUILayout.MinWidth(width * 0.5F));
            changed |= EditorGUIUtil.IntField(null, ref info.value, GUILayout.MinWidth(width * 0.3F));
            return(changed);
        }
示例#4
0
        private bool DrawColumn()
        {
            bool changed     = false;
            int  columnSize  = table.isHorizontal? table.GetMaxPerLine(): table.columnCount;
            int  contentSize = table.columnCount;

            for (int c = 0; c < columnSize; c++)
            {
                EditorGUILayout.BeginVertical();
                changed |= EditorGUIUtil.ObjectField <UITableCell>(ref table.columnPrefab[c], true, GUILayout.ExpandWidth(false), H_Option);
                changed |= EditorGUIUtil.Popup <UITableLayout.HAlign>(ref table.haligns[c], EnumUtil.Values <UITableLayout.HAlign>(), GUILayout.Width(WIDTH - 20), H_Option);
                changed |= EditorGUIUtil.IntField(null, ref table.columnWidth[c], GUILayout.Width(WIDTH - 20), H_Option);
                EditorGUILayout.LabelField(c.ToString(), EditorStyles.boldLabel, W_Option, H_Option);
                int row = table.rowCount;
                if (c < contentSize)
                {
                    for (int r = 0; r < row; r++)
                    {
                        changed |= DrawCell(r, c);
                    }

                    // Draw Column +/- buttons
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button(new GUIContent("A", "Add Selected"), GUILayout.ExpandWidth(false), H_Option))
                    {
                        AddSelected(c, UITableLayout.Arrangement.Vertical);
                        changed = true;
                    }
                    if (GUILayout.Button("+", GUILayout.ExpandWidth(false), H_Option))
                    {
                        #pragma warning disable 0618
                        table.AddColumn(c + 1, new UITableCell[table.rowCount]);
                        #pragma warning restore 0618
                        changed = true;
                    }
                    GUI.enabled = c >= table.columnHeader;
                    if (GUILayout.Button("-", GUILayout.ExpandWidth(false), H_Option))
                    {
                        if (EditorUtility.DisplayDialog("Confirm", "Delete column " + (c + 1), "OK", "Cancel"))
                        {
                            #pragma warning disable 0618
                            table.RemoveColumn(c);
                            #pragma warning restore 0618
                            table.Reposition();
                            changed = true;
                        }
                    }
                    GUI.enabled = true;
                    EditorGUILayout.EndHorizontal();
                }

                EditorGUILayout.EndVertical();
            }
            return(changed);
        }
示例#5
0
        private bool DrawSize()
        {
            bool changed = false;

            if (NGUIEditorTools.DrawHeader("Size"))
            {
                NGUIEditorTools.BeginContents();
                if (EditorGUIUtil.PopupEnum <UITableLayout.HAlign>("Horizontal Align", ref grid.halign, GUILayout.ExpandWidth(false)))
                {
                    for (int i = 0; i < grid.haligns.Length; ++i)
                    {
                        grid.haligns[i] = grid.halign;
                    }
                    changed = true;
                }
                if (EditorGUIUtil.PopupEnum <UITableLayout.VAlign>("Vertical Align", ref grid.valign, GUILayout.ExpandWidth(false)))
                {
                    for (int i = 0; i < grid.valigns.Length; ++i)
                    {
                        grid.valigns[i] = grid.valign;
                    }
                    changed = true;
                }
                changed |= EditorGUIUtil.Vector2Field("Padding", ref grid.padding);
                if (grid.cellMinSize.x == 0 && grid.cellMinSize.y == 0)
                {
                    changed |= EditorGUIUtil.Vector2Field("Cell Size", ref grid.cellSize);
                }
                if (grid.cellSize.x == 0 && grid.cellSize.y == 0)
                {
                    changed |= EditorGUIUtil.Vector2Field("Cell Min Size", ref grid.cellMinSize);
                }
                changed |= EditorGUIUtil.IntField("Total Width", ref grid.totalWidth);
                changed |= EditorGUIUtil.Toggle("Resize Collider", ref grid.resizeCollider, GUILayout.ExpandWidth(false));
                if (grid.resizeCollider && grid.padding != Vector2.zero)
                {
                    EditorGUI.indentLevel += 1;
                    changed |= EditorGUIUtil.Toggle("Expand Collider To Padding", ref grid.expandColliderToPadding, GUILayout.ExpandWidth(false));
                    EditorGUI.indentLevel -= 1;
                }
                NGUIEditorTools.EndContents();
            }
            return(changed);
        }
示例#6
0
        private bool DrawTableHeader()
        {
            bool changed = false;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Size", GUILayout.Width(WIDTH + 10));
            int col = grid.columnCount;

            for (int c = 0; c < col; c++)
            {
                EditorGUILayout.LabelField(c.ToString(), EditorStyles.boldLabel, GUILayout.Width(30));
                changed |= EditorGUIUtil.IntField(null, ref grid.columnWidth[c], GUILayout.Width(WIDTH - 30));
            }
            if (grid.isHorizontal)
            {
                EditorGUILayout.LabelField("", GUILayout.Width(42));
            }
            EditorGUILayout.EndHorizontal();
            return(changed);
        }
示例#7
0
        public override void OnInspectorGUI()
        {
            bool changed = false;

            if (attach.anchor != null)
            {
                Object t = attach.anchor.container != null? (Object)attach.anchor.container: (Object)attach.anchor.uiCamera;
                if (EditorGUIUtil.ObjectField("Target", ref t, true))
                {
                    attach.anchor.uiCamera  = null;
                    attach.anchor.container = null;
                    if (t is Camera)
                    {
                        attach.anchor.uiCamera = t as Camera;
                    }
                    else
                    {
                        attach.anchor.container = t as GameObject;
                    }
                    changed = true;
                }
            }
            if (anchorObj == null && pivotObj == null)
            {
                anchorObj = attach.gameObject;
                // Add pivot GameObject between anchor and anchor children.
                if (anchorObj.transform.childCount == 1 && anchorObj.transform.GetChild(0).GetComponent <UIPivot>() != null)
                {
                    pivotObj = anchorObj.transform.GetChild(0).gameObject;
                }
                else
                {
                    pivotObj     = new GameObject("_pivot");
                    pivotObj.tag = anchorObj.tag;
                    pivotObj.transform.SetParent(anchorObj.transform, false);
                    List <Transform> children = new List <Transform>();
                    foreach (Transform t in anchorObj.transform)
                    {
                        if (t != anchorObj.transform && t != pivotObj.transform)
                        {
                            children.Add(t);
                        }
                    }
                    foreach (Transform t in children)
                    {
                        t.parent = pivotObj.transform;
                    }
                }
                Init();
                changed = true;
            }
            else
            {
                Color oldBg = GUI.backgroundColor;
                GUI.backgroundColor = Color.gray;
                changed            |= EditorGUIUtil.ObjectField <GameObject>("Anchor", ref anchorObj, true);
                changed            |= EditorGUIUtil.ObjectField <GameObject>("Pivot", ref pivotObj, true);
                GUI.backgroundColor = oldBg;
            }

            if (target != null && anchorObj != null && pivotObj != null)
            {
                if (changed)
                {
                    Init();
                }
                if (anchorObj == pivotObj || anchorObj.transform.IsChildOf(pivotObj.transform))
                {
                    EditorGUILayout.HelpBox("Anchor and Pivot should not be in the same GameObject", MessageType.Error);
                }
                else
                {
                    EditorGUILayout.BeginVertical();
                    for (int row = 0; row < 5; row++)
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();
                        for (int col = 0; col < 5; col++)
                        {
                            int   buttonWidth  = 30;
                            int   buttonHeight = 30;
                            Color c            = Color.white;
                            if (row == 0 || row == 4)
                            {
                                buttonHeight = 25;
                                c            = Color.gray;
                            }
                            if (col == 0 || col == 4)
                            {
                                buttonWidth = 25;
                                c           = Color.gray;
                            }
                            GUI.backgroundColor = c;
                            if (GUILayout.Button("A", GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight)))
                            {
                                attach.pivot.pivot = pivots[row, col];
                                attach.anchor.side = sides[row, col];
                                attach.Reposition(sides[row, col], pivots[row, col]);
                                changed = true;
                            }
                        }
                        GUILayout.FlexibleSpace();
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.Space();

                    changed |= EditorGUIUtil.Vector2Field("Relative Offset", ref attach.anchor.relativeOffset);

                    int pixelOffsetX = 0;
                    int pixelOffsetY = 0;
                    if (attach.anchor != null)
                    {
                        pixelOffsetX = (int)attach.anchor.pixelOffset.x;
                        pixelOffsetY = (int)attach.anchor.pixelOffset.y;
                    }
                    if (EditorGUIUtil.IntField("Pixel Offset X", ref pixelOffsetX) ||
                        EditorGUIUtil.IntField("Pixel Offset Y", ref pixelOffsetY))
                    {
                        attach.anchor.pixelOffset = new Vector2(pixelOffsetX, pixelOffsetY);
                        changed = true;
                    }

                    if (changed)
                    {
                        EditorUtil.SetDirty(attach.anchor);
                        EditorUtil.SetDirty(attach.pivot);
                        EditorUtil.SetDirty(attach);
                    }
                }
            }
        }
示例#8
0
        private bool DrawTest()
        {
            showTest = EditorGUILayout.Foldout(showTest, "Test");
            bool changed = false;

            if (showTest)
            {
                EditorGUI.indentLevel += 2;
                EditorGUIUtil.ObjectField <UIFont>("Font", ref testFont, true);
                int row = grid.rowCount;
                int col = grid.columnCount;
                if (EditorGUIUtil.IntField("Font Size", ref fontSize, GUILayout.ExpandWidth(false)))
                {
                    for (int r = 0; r < row; r++)
                    {
                        for (int c = 0; c < col; c++)
                        {
                            UILabel label = grid.GetCell(r, c).GetComponent <UILabel>();
                            if (label != null)
                            {
                                label.transform.localScale = new Vector3(fontSize, fontSize, 1);
                            }
                        }
                    }
                }
                if (EditorGUIUtil.ColorField("Font Color", ref fontColor, GUILayout.ExpandWidth(false)))
                {
                    for (int r = grid.rowHeader; r < row; r++)
                    {
                        for (int c = grid.columnHeader; c < col; c++)
                        {
                            UILabel label = grid.GetCell(r, c).GetComponent <UILabel>();
                            if (label != null)
                            {
                                label.color = fontColor;
                                label.MarkAsChanged();
                            }
                        }
                    }
                }
                Array.Resize(ref testStrings, grid.maxPerLine);
                for (int i = 0; i < grid.maxPerLine; i++)
                {
                    EditorGUIUtil.TextField(i.ToString(), ref testStrings[i], GUILayout.ExpandWidth(false));
                }
                GUI.enabled = testFont != null;
                if (GUILayout.Button("Fill Data"))
                {
                    for (int r = grid.rowHeader; r < row; r++)
                    {
                        for (int c = grid.columnHeader; c < col; c++)
                        {
                            UITableCell cell = grid.GetCell(r, c);
                            if (cell == null)
                            {
                                UILabel label = NGUITools.AddWidget <UILabel>(grid.gameObject);
                                label.bitmapFont = testFont;
                                label.name       = "__TEST__";
                                label.SetText(testStrings[grid.isHorizontal?c:r]);
                                label.transform.localScale = new Vector3(fontSize, fontSize, 1);
                                label.color = fontColor;
                                label.MarkAsChanged();
                                UILabelCell lc = label.gameObject.AddComponent <UILabelCell>();
                                lc.label = label;
                                grid.SetCell(r, c, lc);
                            }
                        }
                    }
                    changed = true;
                }
                GUI.enabled            = true;
                EditorGUI.indentLevel -= 2;
            }
            return(changed);
        }
示例#9
0
        public override void OnInspectorGUI()
        {
            object current = null;

            Color contentColor = GUI.contentColor;
            Color bgColor      = GUI.backgroundColor;
            Color c1           = BG_COLOR1;
            Color c2           = BG_COLOR1;

            foreach (UIWidget w in widgets)
            {
                if (w.GetType() == typeof(UIWidget) || w.gameObject == null)
                {
                    continue;
                }
                UISprite  s     = w as UISprite;
                UILabel   l     = w as UILabel;
                UITexture t     = w as UITexture;
                int       depth = w.depth;

                #pragma warning disable 0253
                bool toggle = false;
                if (s != null)
                {
                    if (s.atlas == null)
                    {
                        continue;
                    }
                    if (s.atlas != current)
                    {
                        current = s.atlas;
                        toggle  = true;
                    }
                }
                else if (l != null)
                {
                    if (l.bitmapFont != current)
                    {
                        current = l.bitmapFont;
                        toggle  = true;
                    }
                }
                else if (t != null)
                {
                    if (t.mainTexture != current)
                    {
                        current = t.mainTexture;
                        toggle  = true;
                    }
                }
                else
                {
                    toggle  = true;
                    current = null;
                }
                #pragma warning restore 0253
                if (toggle)
                {
                    c2 = c2 != BG_COLOR1? BG_COLOR1: BG_COLOR2;
                }
                c1 = c2;

                if (atlasSel != null)
                {
                    c1 = s != null && s.atlas == atlasSel? SEL_BG_COLOR: BG_COLOR1;
                }
                else if (fontSel != null)
                {
                    c1 = l != null && l.bitmapFont == fontSel? SEL_BG_COLOR: BG_COLOR1;
                }
                if (w.gameObject == Selection.activeGameObject)
                {
                    c1 = SEL_BG_COLOR;
                }
                GUI.backgroundColor = c1;
                if (c1 == BG_COLOR1)
                {
                    GUI.contentColor = TXT_COLOR1;
                }
                else if (c1 == BG_COLOR2)
                {
                    GUI.contentColor = TXT_COLOR2;
                }
                else if (c1 == SEL_BG_COLOR)
                {
                    GUI.contentColor = SEL_TXT_COLOR;
                }

                EditorGUILayout.BeginHorizontal();
                string widgetName = w.name;
                if (s != null)
                {
                    if (s.atlas != null)
                    {
                        widgetName = string.Format("[ATLAS {0}] {2} ({1})", s.atlas.name, s.spriteName, w.name);
                    }
                }
                else if (l != null)
                {
                    if (l.trueTypeFont != null)
                    {
                        widgetName = string.Format("[TTF {0}] {1}", l.trueTypeFont.name, w.name);
                    }
                    else if (l.bitmapFont != null)
                    {
                        widgetName = string.Format("[BMF {0}] {1}", l.bitmapFont.name, w.name);
                    }
                    else
                    {
                        widgetName = string.Format("FNT {0}", w.name);
                    }
                }
                else if (t != null)
                {
                    if (t.mainTexture != null)
                    {
                        widgetName = string.Format("[TEX {0}] {1}", t.mainTexture.name, t.name);
                    }
                    else
                    {
                        widgetName = string.Format("TEX {0}", t.name);
                    }
                }
                bool active = w.gameObject.activeInHierarchy;
                if (active || !showActiveOnly)
                {
                    Color fgColor = Color.white;
                    if (!active)
                    {
                        fgColor = INACTIVE_TXT_COLOR;
                    }
                    GUI.contentColor = fgColor;
                    if (GUILayout.Button(widgetName, EditorStyles.objectField))
                    {
                        Select(w);
                    }
                    if (EditorGUIUtil.IntField(null, ref depth, GUILayout.Width(40)))
                    {
                        w.depth = depth;
                        CompatibilityEditor.SetDirty(w);
                    }
                }
                EditorGUILayout.EndHorizontal();
            }

            GUI.backgroundColor = bgColor;
            GUI.contentColor    = contentColor;
        }