示例#1
0
        private void UpdateBubbleSize()
        {
            if (bubble == null)
            {
                return;
            }
            Vector2 size = NGUIUtil.GetSize(label) + borderSize;

            bubble.width  = (int)Mathf.Max(size.x, label.width + borderSize.x);
            bubble.height = (int)size.y;
        }
示例#2
0
        private void RefreshBounds()
        {
            Bounds  bounds = NGUIUtil.CalculateAbsoluteWidgetBounds(transform, bound);
            Vector3 extent = bounds.extents;
            Vector3 center = bounds.center;

            pos1      = center + new Vector3(-extent.x * SCROLL_BOUND, -extent.y * SCROLL_BOUND, 0);
            pos2      = center + new Vector3(-extent.x * SCROLL_BOUND, extent.y * SCROLL_BOUND, 0);
            pos3      = center + new Vector3(extent.x * SCROLL_BOUND, -extent.y * SCROLL_BOUND, 0);
            pos4      = center + new Vector3(extent.x * SCROLL_BOUND, extent.y * SCROLL_BOUND, 0);
            scrollPos = panel.cachedTransform.position;
        }
示例#3
0
 public void RefreshSeed(object seed)
 {
     if (IsVisible())
     {
         this.seed = seed;
         GetContents(seed, () =>
         {
             SetContents();
             NGUIUtil.Reposition(transform);
         });
     }
 }
示例#4
0
        private UITableCell CreateLabel(string text, int i)
        {
            UILabel label = NGUIUtil.InstantiateWidget(grid.transform, titleLabelPrefab.gameObject).GetComponent <UILabel>();

            label.name = "Title" + i;
            label.SetText(text);
            label.MarkAsChanged();
            label.gameObject.SetActive(true);
            UILabelCell cell = label.gameObject.AddComponent <UILabelCell>();

            cell.label = label;
            return(cell);
        }
示例#5
0
 private void SetCell(int r, int c, UITableCell cell)
 {
     if (cell != null)
     {
         int oldIndex = table.GetIndex(cell);
         if (oldIndex >= 0)
         {
             table.components[oldIndex] = null;
         }
         NGUIUtil.DisableAnchor(cell.transform);
     }
     table.SetCell(r, c, cell);
 }
示例#6
0
        override public void OnInspectorGUI()
        {
            bool changed = varInspector.OnInspectorGUI();

            if (changed)
            {
                NGUIUtil.DisableAnchor(layout.top);
                NGUIUtil.DisableAnchor(layout.center);
                NGUIUtil.DisableAnchor(layout.bottom);
                NGUIUtil.DisableAnchor(layout.left);
                NGUIUtil.DisableAnchor(layout.right);
                layout.InvalidateLayout();
                EditorUtil.SetDirty(target);
            }
        }
示例#7
0
        public void SetVisible(bool visible)
        {
            if (uiRoot == null)
            {
                return;
            }
            if (!tabButton.isEnabled == visible)
            {
                return;
            }
            tabButton.SetButtonActive(!visible);
            if (visible)
            {
                GetComponentInParent <UIPanel>().ArrangeRenderQueue();
                GetContents(seed, () =>
                {
                    // tab selection may be changed after GetContents() is called
                    if (!tabButton.isEnabled)
                    {
                        PreOpen();
                        eventReg.RegisterEvents();
                        uiRoot.SetActive(true);
                        if (buttons != null)
                        {
                            buttons.enabled = true;
                        }
                        SetContents();
                        NGUIUtil.Reposition(transform);
                    }
                });
            }
            else
            {
                if (tabButton.isEnabled)
                {
                    uiRoot.SetActive(false);
                    if (buttons != null)
                    {
                        buttons.enabled = false;
                    }
                    eventReg.DeregisterEvents();
                    PostClose();
                }
            }

            TabSelectChange(visible);
        }
示例#8
0
        /**
         * Row중 UILabel인 경우 text color를 바꾸어준다.
         * @param row row 값은 title row를 포함한 실제 row번호(zero-based)
         */
        public static void SetRowColor(this UITableLayout table, int row, Color color)
        {
            string colorStr = NGUIUtil.ConvertColor2Str(color);

            for (int col = table.columnHeader; col < table.columnCount; col++)
            {
                UITableCell c = table.GetCell(row + table.rowHeader, col);
                if (c != null)
                {
                    UILabel label = c.GetComponent <UILabel>();
                    if (label != null)
                    {
                        label.SetText(colorStr + label.text);
                    }
                }
            }
        }
示例#9
0
        void Update()
        {
            if (grid == null || !invalid)
            {
                return;
            }
            float delta = Time.deltaTime;

            if (rowCount == 0)
            {
                Init();
            }
            for (int r = 0; r < rowCount; r++)
            {
                float old = rowDelay[r];
                rowDelay[r] = Math.Min(rowDelay[r] + delta * speed, 1);
                float time          = Math.Max(0, rowDelay[r]);
                float interpolation = TweenEasingFunctions.GetFunction(easeType)(time);
                for (int c = 0; c < colCount; c++)
                {
                    Transform t = grid.GetCell(r, c);
                    if (t != null)
                    {
                        animator(r, t, cellScales[r, c], cellPos[r, c], interpolation);
                    }
                }
                if (animateBackground)
                {
                    Transform bg = grid.GetBackground(r);
                    if (bg != null)
                    {
                        animator(r, bg, bgScales[r], bgPos[r], interpolation);
                    }
                }
                if (r >= grid.rowHeader && old <= 0 && time > 0)
                {
                    foreach (UITableAnimEventListener l in listeners)
                    {
                        l.OnRowAnimBegin(r - grid.rowHeader);
                    }
                }
                if (r >= grid.rowHeader && old < 1 && time >= 1)
                {
                    foreach (UITableAnimEventListener l in listeners)
                    {
                        l.OnRowAnimEnd(r - grid.rowHeader);
                    }
                }
            }
            if (rowCount > 0 && rowDelay[rowCount - 1] >= 1)
            {
                for (int r = 0; r < rowCount; r++)
                {
                    Transform bg = grid.GetBackground(r);
                    if (bg != null)
                    {
                        NGUIUtil.UpdateCollider(bg);
                    }
                }
                invalid = false;
                foreach (UITableAnimEventListener l in listeners)
                {
                    l.OnAnimEnd();
                }
            }
        }
示例#10
0
        override protected void DoLayout()
        {
//			if (this.model == null) {
//				return new Bounds();
//			}
            InitArray();
            Rect bound = new Rect();

            CalculateBound(bound);
            int row = rowCount;
            int col = columnCount;

            UITablePrefabs prefabs = GetPrefabs();
            float          pixely  = 0;

            for (int r = 0; r < row; r++)
            {
                float pixelx    = 0;
                bool  activeRow = false; // inactive row is removed from layout computation
                for (int c = 0; c < col; c++)
                {
                    UITableCell cell = GetCell(r, c);
                    if (cell != null && cell.gameObject.activeInHierarchy)
                    {
                        Transform t = cell.transform;
                        if (!t.IsChildOf(transform))
                        {
                            t.SetParent(transform, false);
                        }
                        Vector3 point     = bounds[r, c].min;
                        Vector3 size      = bounds[r, c].size;
                        float   halignPad = 0;
                        float   valignPad = 0;
                        Vector3 pos       = t.localPosition;
                        if (haligns[c] == HAlign.None)
                        {
                            if (r >= rowHeader && c >= columnHeader)
                            {
                                UITableCell prefab = prefabs.GetPrefab(r, c);
                                if (prefab != null)
                                {
                                    if (prefab == defaultPrefab)
                                    {
                                        pos.x = pixelx + prefab.transform.localPosition.x;
                                    }
                                    else
                                    {
                                        pos.x = prefab.transform.localPosition.x;
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (haligns[c] == HAlign.Center)
                            {
                                halignPad = (maxWidths[c] - size.x) / 2f;
                            }
                            else if (haligns[c] == HAlign.Right)
                            {
                                halignPad = maxWidths[c] - size.x;
                            }
                            pos.x = pixelx - point.x + halignPad;
                        }
                        if (valigns[r] == VAlign.None)
                        {
                            if (r >= rowHeader && c >= columnHeader)
                            {
                                UITableCell prefab = prefabs.GetPrefab(r, c);
                                if (prefab != null)
                                {
                                    if (prefab == defaultPrefab)
                                    {
                                        pos.y = pixely + prefab.transform.localPosition.y;
                                    }
                                    else
                                    {
                                        pos.y = prefab.transform.localPosition.y;
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (valigns[r] == VAlign.Center)
                            {
                                valignPad = (maxHeights[r] - size.y) / 2f;
                            }
                            else if (valigns[r] == VAlign.Bottom)
                            {
                                valignPad = maxHeights[r] - size.y;
                            }
                            pos.y = pixely - (point.y + size.y) - valignPad;
                        }

                        t.SetLocalPosition(pos, 0.01f);
                        NGUIUtil.ApplyPivot(t);

                        // update Collider Bound
                        if (resizeCollider)
                        {
                            BoxCollider box = t.GetComponentInChildren <BoxCollider>();
                            if (box != null)
                            {
                                Vector3 center = box.center;
                                center.x = pixelx + maxWidths[c] * 0.5f;
                                center.y = pixely - maxHeights[r] * 0.5f;
                                Vector3 boxSize = box.size;
                                boxSize.x = maxWidths[c];
                                boxSize.y = maxHeights[r];
                                if (expandColliderToPadding)
                                {
                                    if (c < col - 1)
                                    {
                                        boxSize.x += padding.x;
                                        center.x  += padding.x * 0.5f;
                                    }
                                    if (r < row - 1)
                                    {
                                        boxSize.y += padding.y;
                                        center.y  -= padding.y * 0.5f;
                                    }
                                }
                                center     = transform.TransformSpace(center, t);
                                center.z   = box.center.z;
                                box.center = center;
                                box.size   = boxSize;
                            }
                            else
                            {
                                BoxCollider2D box2d = t.GetComponentInChildren <BoxCollider2D>();
                                if (box2d != null)
                                {
                                    Vector2 center = box2d.offset;
                                    center.x = pixelx + maxWidths[c] * 0.5f;
                                    center.y = pixely - maxHeights[r] * 0.5f;
                                    Vector2 boxSize = box2d.size;
                                    boxSize.x = maxWidths[c];
                                    boxSize.y = maxHeights[r];
                                    if (expandColliderToPadding)
                                    {
                                        if (c < col - 1)
                                        {
                                            boxSize.x += padding.x;
                                            center.x  += padding.x * 0.5f;
                                        }
                                        if (r < row - 1)
                                        {
                                            boxSize.y += padding.y;
                                            center.y  -= padding.y * 0.5f;
                                        }
                                    }
                                    center       = transform.TransformSpace(center, t);
                                    box2d.offset = center;
                                    box2d.size   = boxSize;
                                }
                            }
                        }
                        //					if (bound.width != 0) {
                        //						bound.x = Math.Min(bound.x, pos.x);
                        //					}
                        //					if (bound.height != 0) {
                        //						bound.y = Math.Max(bound.y, pos.y);
                        //					}
                    }
                    Vector3 extent = bounds[r, c].extents;
                    bounds[r, c].center = new Vector2(pixelx + extent.x, pixely - extent.y);

                    cellPos[r, c] = new Vector2(pixelx, pixely);
                    activeRow    |= cell == null || cell.gameObject.activeInHierarchy;
                    pixelx       += maxWidths[c] + padding.x;
                }
                if (activeRow)
                {
                    pixely += -maxHeights[r] - padding.y;
                }
            }

            if (NGUIUtil.IsValid(bound))
            {
//				UIDraggablePanel drag = NGUITools.FindInParents<UIDraggablePanel>(gameObject);
//				if (drag != null) drag.UpdateScrollbars(true);
            }
            else
            {
                bound = new Rect();
            }
            if (propagateReposition)
            {
                NGUIUtil.Reposition(transform);
            }
        }
示例#11
0
 public static void ResizeCollider()
 {
     NGUIUtil.UpdateCollider(Selection.activeGameObject.transform);
 }
示例#12
0
        override protected void DoLayout()
        {
            Bounds topBound    = GetBounds(top);
            Bounds bottomBound = GetBounds(bottom);
            Bounds leftBound   = GetBounds(left);
            Bounds rightBound  = GetBounds(right);

            Vector3 topPoint    = topBound.min;
            Vector3 topSize     = topBound.size;
            Vector3 bottomPoint = bottomBound.min;
            Vector3 bottomSize  = bottomBound.size;
            Vector3 leftPoint   = leftBound.min;
            Vector3 leftSize    = leftBound.size;
            Vector3 rightPoint  = rightBound.min;
            Vector3 rightSize   = rightBound.size;

            // Align Top
            if (top != null)
            {
                Vector3 topPos = top.localPosition;
                topPos.x = -topPoint.x;
                topPos.y = -topPoint.y;
                top.SetLocalPosition(topPos, 0.01f);
                NGUIUtil.ApplyPivot(top);
            }

            // Align Bottom
            if (bottom != null)
            {
                Vector3 botPos = bottom.localPosition;
                botPos.x = -bottomPoint.x;
                botPos.y = -height - bottomSize.y - bottomPoint.y;
                bottom.SetLocalPosition(botPos, 0.01f);
                bottom.localPosition = botPos;
                NGUIUtil.ApplyPivot(bottom);
            }

            // Align Left
            if (left != null)
            {
                Vector3 leftPos = left.localPosition;
                leftPos.x = -leftPoint.x;
                leftPos.y = -leftPoint.y + topSize.y;
                left.SetLocalPosition(leftPos, 0.01f);
                NGUIUtil.ApplyPivot(left);
            }

            // Align Right
            if (right != null)
            {
                Vector3 rightPos = right.localPosition;
                rightPos.x = width - rightPoint.x - rightSize.x;
                rightPos.y = -rightPoint.y + topSize.y;
                right.SetLocalPosition(rightPos, 0.0001f);
                NGUIUtil.ApplyPivot(right);
            }

            if (center != null)
            {
                Vector3 pos = center.transform.localPosition;
                pos.x = 0;
                pos.y = 0;
                center.SetLocalPosition(pos, 0.0001f);

                float x = (leftSize.x - rightSize.x) / 2;
                float y = (topSize.y - bottomSize.y) / 2;
                float w = width - (leftSize.x + rightSize.x);
                float h = height + topSize.y + bottomSize.y;
                NGUIUtil.SetBoundingBox(center, new Rect(x, y, w, h));
                NGUIUtil.ApplyPivot(center);
            }

//			return new Bounds(new Vector3(width*0.5f, height*0.5f, 0), new Vector3(0, width, -height));
        }