Ejemplo n.º 1
0
        /**
         * Cell이 비었을 경우 prefab으로 새로 생성하여 Cell에 집어넣는다.
         * cell 값이 GameObject일 경우 prefab이라고 가정하고 새로 생성한다.
         * 이외의 값일 경우 ToString()을 사용하여 Label을 넣는다.
         */
        private void SetCellValue(UITablePrefabs prefabs, int row, int col, object cellValue, Action <UITableCell> initFunc)
        {
            UITableCell cell = GetCell(row, col);

            if (cellValue == null)
            {
                if (cell != null)
                {
                    cell.gameObject.SetActive(false);
                }
                return;
            }

            // Instantiate Cell
            if (cell == null)
            {
                cell = prefabs.Instantiate(row, col);
                if (!cell.transform.IsChildOf(transform))
                {
                    cell.transform.SetParent(transform, false);
                }
            }
            // Set Cell Value
            SetCell(row, col, cell);

            UITableCell.SetValue(this, cell, row - rowHeader, col - columnHeader, cellValue, initFunc);
        }
Ejemplo n.º 2
0
        public void RefreshContents()
        {
            if (model == null)
            {
                emptyObj.SetActiveEx(true);
                return;
            }
            List <object> sel = GetSelectedDataList <object>();

            emptyObj.SetActiveEx(model.IsEmpty());
            AssertDimension();
            UITablePrefabs prefabs = GetPrefabs();

            if (isHorizontal)
            {
                for (int r = 0; r < model.GetRowCount(); r++)
                {
                    for (int c = 0; c < model.GetColumnCount(); c++)
                    {
                        object cellValue = model.GetValue(r, c);
                        SetCellValue(prefabs, r + rowHeader, c + columnHeader, cellValue, initFunc);
                    }
                }
                /*  여분의 Row를 삭제한다. */
                for (int r = rowCount - 1; r >= rowHeader + model.GetRowCount(); r--)
                {
                    #pragma warning disable 0618
                    RemoveRow(r);
                    #pragma warning restore 0618
                }
            }
            else
            {
                for (int c = 0; c < model.GetColumnCount(); c++)
                {
                    for (int r = 0; r < model.GetRowCount(); r++)
                    {
                        object cellValue = model.GetValue(r, c);
                        SetCellValue(prefabs, r + rowHeader, c + columnHeader, cellValue, initFunc);
                    }
                }
                for (int c = columnCount - 1; c >= columnHeader + model.GetColumnCount(); c--)
                {
                    #pragma warning disable 0618
                    RemoveColumn(c);
                    #pragma warning restore 0618
                }
            }
            if (enabled)
            {
                DoLayout();
            }
            SelectCell <object>(o => sel.Contains(o));

            foreach (UITableEventListener l in listeners)
            {
                l.OnModelChanged();
            }
        }
Ejemplo n.º 3
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);
            }
        }