Ejemplo n.º 1
0
        public void OnGridGUI()
        {
            if (grid == null)
            {
                return;
            }

            bool changed = false;

            if (grid.maxPerLine <= 0)
            {
                grid.maxPerLine = 1;
                changed         = true;
            }

            if (changed)
            {
                grid.InitArray();
            }

            changed    |= DrawTableStructure();
            changed    |= DrawSize();
            GUI.enabled = true;

            if (changed)
            {
                grid.InitArray();
                EditorUtil.SetDirty(grid);
                if (grid.enabled)
                {
                    NGUIUtil.Reposition(grid.transform);
                    grid.Reposition();
                }
            }
        }
Ejemplo n.º 2
0
        void OnEnable()
        {
            this.layout = (UIBorderLayout)target;
            this.layout.InvalidateLayout();
            SerializedObject obj = new SerializedObject(target);

            varInspector = new SerializedInspector(obj, "top", "center", "bottom", "left", "right", "width", "height", "pivot");
            NGUIUtil.Reposition(layout.transform);
        }
Ejemplo n.º 3
0
 public void RefreshSeed(object seed)
 {
     if (IsVisible())
     {
         this.seed = seed;
         GetContents(seed, () =>
         {
             SetContents();
             NGUIUtil.Reposition(transform);
         });
     }
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
            }
        }