///// <summary>
        ///// 合并
        ///// </summary>
        ///// <param name="cell"></param>
        //public void OnMerge(KGUI_TableCell cell, float spaceing)
        //{
        //    //是否行相邻
        //    OnRowMerge(cell, spaceing);

        //    //是否列相邻
        //    OnCloumMerge(cell, spaceing);
        //}

        ///// <summary>
        ///// 是否行相邻
        ///// </summary>
        ///// <param name="cell"></param>
        ///// <returns></returns>
        //public bool OnRowNeighbor(KGUI_TableCell cell)
        //{
        //    //如果数组的最后一个,不跟他相邻的话,则直接跳过
        //    float row = 0;

        //    foreach (var item in Cells)
        //    {
        //        //找到最大的行值
        //        if (item.Position.x > row)
        //            row = item.Position.x;
        //    }

        //    //判断是否相邻
        //    if (Mathf.Abs(cell.Position.x - row) != 1 || Mathf.Abs(cell.Position.x - Position.x) != 1) return false;

        //    return true;
        //}

        //public bool OnCloumNeighbor(KGUI_TableCell cell)
        //{
        //    //if (cell.Position.y - Position.y != 1) return false;

        //    float cloum = 0;

        //    foreach (var item in Cells)
        //    {
        //        if (item.Position.y > cloum)
        //            cloum = item.Position.y;
        //    }

        //    //不相邻,则直接跳过
        //    if (Mathf.Abs(cell.Position.y - cloum) != 1 || cell.Position.y - Position.y != 1) return false;

        //    return true;
        //}
        #endregion

        /// <summary>
        /// 行合并
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="spaceing"></param>
        /// <returns></returns>
        public bool OnRowMerge(KGUI_TableCell cell, float spaceing)
        {
            ////如果不在同一列的话,则直接跳过
            //if (Position.y != cell.Position.y|| !OnRowNeighbor(cell))
            //    //判断是否行相邻
            //    return false;

            //如果不相邻,则跳过
            //if (!OnRowNeighbor(cell)) return false;
            if (cell == null)
            {
                return(false);
            }

            if (!Cells.Contains(cell))
            {
                //进行合并
                Cells.Add(cell);
                cell.OnHide();
            }

            //重新计算高度
            Size = new Vector2(Size.x, cell.Size.y + Size.y + spaceing);

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// 合并列
        /// </summary>
        /// <param name="row"></param>
        /// <param name="startCloumn"></param>
        /// <param name="endCloumn"></param>
        public void MergeCloumn(int row, int startCloumn, int endCloumn)
        {
            ////获取到这个范围内的所有列,判断是否存在已经隐藏的,如果存在,则直接跳过
            //for (int i = startCloumn; i < endCloumn; i++)
            //{
            //    if (Rows[row].Cells[i].IsHide) return;//如果存在隐藏的,则直接跳过。表示所选的已经有合并了
            //}

            KGUI_TableCell startCell = GetTableCell(new Vector2Int(row, startCloumn));
            //判断起始单元格,是否还存在其他的行

            int _row;

            if (startCell.IsExistRow(out _row))
            {
                for (int i = row + 1; i <= _row; i++)
                {
                    //将该行的所有列都注释掉
                    for (int j = startCloumn; j <= endCloumn; j++)
                    {
                        startCell.AddCell(GetTableCell(new Vector2Int(i, j)));
                    }
                }
            }

            //如果存在,则也将其他的行包含过去,执行合并单元格
            for (int i = startCloumn + 1; i <= endCloumn; i++)
            {
                //合并列
                startCell.OnCloumMerge(GetTableCell(new Vector2Int(row, i)), spacing);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 设置行高
        /// </summary>
        /// <param name="tableCell"></param>
        public void SetRowHeight(KGUI_TableCell tableCell, float height)
        {
            //算出单元格
            float sumHeight = 0;//设置总高度

            //获取到所有的行
            for (int i = 0; i < Rows.Count; i++)
            {
                Rows[i].transform.localPosition = new Vector3(-rowParent.sizeDelta.x / 2, sumHeight, Rows[i].transform.localPosition.z);

                //如果在同一行,不用遍历全部的列,只需要遍历第一个元素即可
                if (Rows[i].Cells[0].Position.x == tableCell.Position.x)
                {
                    //则设置此行
                    Rows[i].Rect.sizeDelta = new Vector2(Rows[i].Size.x, height);//设置高度
                    //设置该列的所有列高
                    for (int j = 0; j < Rows[i].Cells.Count; j++)
                    {
                        KGUI_TableCell cell = Rows[i].Cells[j];

                        cell.SetSize(new Vector2(cell.Size.x, height));
                    }
                }

                sumHeight -= Rows[i].Size.y + spacing;//高度
            }

            //根据行列宽与行列数,计算出高度,以及间隔
            rowParent.sizeDelta = new Vector2(rowParent.sizeDelta.x, Mathf.Abs(sumHeight));//重新计算出总高度
        }
Beispiel #4
0
        /// <summary>
        /// 设置列宽
        /// </summary>
        /// <param name="tableCell"></param>
        public void SetColumnWidth(KGUI_TableCell tableCell, float width)
        {
            //获取到所有的行
            for (int i = 0; i < Rows.Count; i++)
            {
                //算出单元格
                float rowX = 0;

                //遍历所有的列
                for (int j = 0; j < Rows[i].Cells.Count; j++)
                {
                    KGUI_TableCell cell = Rows[i].Cells[j];
                    //计算坐标
                    cell.transform.localPosition = new Vector3(rowX, 0, 0);

                    //如果是同一列
                    if (cell.Position.y == tableCell.Position.y)
                    {
                        //设置宽度
                        cell.SetSize(new Vector2(width, cell.Size.y));
                        //并且重新计算排榜
                    }

                    rowX += cell.Size.x + spacing;
                }
            }
        }
 /// <summary>
 /// 添加单元格
 /// </summary>
 /// <param name="cell"></param>
 public void AddCell(KGUI_TableCell cell)
 {
     if (!Cells.Contains(cell))
     {
         Cells.Add(cell);
         cell.OnHide();
     }
 }
Beispiel #6
0
        public void Remove(KGUI_TableCell cell)
        {
            if (!Cells.Contains(cell))
            {
                return;
            }

            Cells.Remove(cell);
        }
Beispiel #7
0
        public void Add(KGUI_TableCell cell)
        {
            if (Cells.Contains(cell))
            {
                return;
            }

            Cells.Add(cell);
        }
Beispiel #8
0
        public void AddData(Vector2Int vector, string data)
        {
            KGUI_TableCell cell = GetTableCell(vector);

            if (cell == null)
            {
                return;
            }

            cell.SetCell(data);
        }
        /// <summary>
        /// 列合并
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="spaceing"></param>
        /// <returns></returns>
        public bool OnCloumMerge(KGUI_TableCell cell, float spaceing)
        {
            if (cell == null)
            {
                return(false);
            }

            if (!Cells.Contains(cell))
            {
                Cells.Add(cell);
                cell.OnHide();
            }

            Size = new Vector2(cell.Size.x + Size.x + spaceing, Size.y);

            return(true);
        }
Beispiel #10
0
        /// <summary>
        /// 清空数据
        /// </summary>
        /// <param name="keys"></param>
        public void ClearData(List <Vector2Int> keys)
        {
            if (keys == null)
            {
                return;
            }

            foreach (var item in keys)
            {
                KGUI_TableCell cell = GetTableCell(item);
                if (cell == null || cell.IsHide)
                {
                    continue;
                }

                cell.SetCell("");
            }
        }
Beispiel #11
0
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="datas"></param>
        public void AddData(Dictionary <Vector2Int, string> datas)
        {
            if (datas == null)
            {
                return;
            }

            foreach (var data in datas)
            {
                KGUI_TableCell cell = GetTableCell(data.Key);
                if (cell == null || cell.IsHide)
                {
                    continue;
                }

                cell.SetCell(data.Value);
            }
        }
Beispiel #12
0
        /// <summary>
        /// 合并行
        /// </summary>
        /// <param name="cloumn"></param>
        /// <param name="startRow"></param>
        /// <param name="endRow"></param>
        public void MergeRow(int cloumn, int startRow, int endRow)
        {
            //获取到这个范围内的所有列,判断是否存在已经隐藏的,如果存在,则直接跳过
            for (int i = startRow; i < startRow; i++)
            {
                //如果存在隐藏的,则直接跳过。表示所选的已经有合并了
                if (Rows[i].Cells[cloumn].IsHide)
                {
                    Debug.Log("已经存在合并的");
                    return;
                }
                ;
            }

            KGUI_TableCell startCell = GetTableCell(new Vector2Int(startRow, cloumn));

            int _cloumn;

            if (startCell.IsExistRow(out _cloumn))
            {
                for (int i = cloumn + 1; i <= _cloumn; i++)
                {
                    //将该列的所有行都注释掉
                    for (int j = startRow; j <= endRow; j++)
                    {
                        startCell.AddCell(GetTableCell(new Vector2Int(j, i)));
                    }
                }
            }

            //如果存在,则也将其他的行包含过去,执行合并单元格
            for (int i = startRow + 1; i <= endRow; i++)
            {
                //合并列
                startCell.OnRowMerge(GetTableCell(new Vector2Int(i, cloumn)), spacing);
            }
        }
Beispiel #13
0
        public override void OnInspectorGUI()
        {
            if (style == null)
            {
                style = new GUIStyle(GUI.skin.name);
                style.normal.textColor = GUI.skin.label.normal.textColor;
                style.fontStyle        = FontStyle.Bold;
                style.alignment        = TextAnchor.UpperLeft;
            }

            if (cellStyle == null)
            {
                cellStyle = new GUIStyle(GUI.skin.box);
                cellStyle.normal.textColor = Color.white;
                cellStyle.alignment        = TextAnchor.MiddleCenter;
            }

            GUILayout.Space(10);

            table.TableName = EditorGUILayout.TextField("表格名称:", table.TableName);

            table.spacing = EditorGUILayout.FloatField("表格间距:", table.spacing);
            GUILayout.Space(10);

            EditorGUILayout.BeginHorizontal();

            table.Ranks.x = EditorGUILayout.IntField("行数:", table.Ranks.x);
            table.Ranks.y = EditorGUILayout.IntField("列数:", table.Ranks.y);
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(10);

            EditorGUILayout.BeginHorizontal();
            table.cellSize.x = EditorGUILayout.FloatField("宽:", table.cellSize.x);
            table.cellSize.y = EditorGUILayout.FloatField("高:", table.cellSize.y);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginVertical();

            if (GUILayout.Button("生成表格", GUILayout.Width(100), GUILayout.Height(25)))
            {
                //生成表格
                table.CreateTable();
            }

            GUILayout.Space(20);

            EditorGUILayout.EndVertical();

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.LabelField("表格样式如下:");

            EditorGUILayout.BeginVertical();

            //绘制表格
            for (int i = 0; i < table.Rows.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();

                //每一行的开始,绘制一个很小的按钮

                //每行都绘制出来
                for (int j = 0; j < table.Rows[i].Cells.Count; j++)
                {
                    KGUI_TableCell cell = table.Rows[i].Cells[j];

                    if (cell.IsHide)
                    {
                        GUILayout.Box(cell.Position.ToString(), GUILayout.Width(100), GUILayout.Height(20));
                    }
                    else
                    {
                        if (GUILayout.Button(cell.Position.ToString(), GUILayout.Width(100), GUILayout.Height(20)))
                        {
                            KGUI_Keyboard.Keybd_event(13, 0, 0, 0);
                            columnWidth = cell.Size.x;
                            rowHeight   = cell.Size.y;

                            _cell   = cell;
                            IsClick = true;
                        }
                    }


                    GUILayout.Space(0);
                }

                GUILayout.Space(0);

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndVertical();

            GUILayout.Space(20);

            EditorGUILayout.BeginVertical();

            if (IsClick && _cell != null)
            {
                EditorGUI.BeginChangeCheck();

                EditorGUILayout.LabelField("坐标:", _cell.Position.ToString());
                EditorGUILayout.LabelField("大小:", _cell.Size.ToString());

                text = EditorGUILayout.TextField("文本信息:", _cell.GetCell());

                _cell.SetCell(text);

                GUILayout.Space(10);

                columnWidth = EditorGUILayout.FloatField("列宽:", columnWidth);

                if (GUILayout.Button("设置列宽"))
                {
                    //设置列宽
                    table.SetColumnWidth(_cell, columnWidth);
                }

                GUILayout.Space(10);

                rowHeight = EditorGUILayout.FloatField("行高:", rowHeight);
                if (GUILayout.Button("设置行高"))
                {
                    table.SetRowHeight(_cell, rowHeight);
                }

                EditorGUI.EndChangeCheck();
            }

            GUILayout.Space(20);

            EditorGUILayout.EndVertical();

            EditorGUILayout.LabelField("合并单元格:");

            mergeType = (MergeType)EditorGUILayout.EnumPopup("合并类型:", mergeType);
            switch (mergeType)
            {
            case MergeType.Row:

                value = EditorGUILayout.IntField("Row:", value);

                startValue = EditorGUILayout.IntField("startCloumn:", startValue);
                endValue   = EditorGUILayout.IntField("endCloumn:", endValue);

                if (GUILayout.Button("合并", GUILayout.Width(100), GUILayout.Height(22)))
                {
                    //设置列宽
                    table.MergeCloumn(value, startValue, endValue);
                }

                break;

            case MergeType.Cloumn:

                value = EditorGUILayout.IntField("Cloumn:", value);

                startValue = EditorGUILayout.IntField("startRow:", startValue);
                endValue   = EditorGUILayout.IntField("endRow:", endValue);

                if (GUILayout.Button("合并", GUILayout.Width(150), GUILayout.Height(25)))
                {
                    //设置列宽
                    table.MergeRow(value, startValue, endValue);
                }
                break;

            default:
                break;
            }

            GUILayout.Space(20);

            table.textColor = EditorGUILayout.ColorField("单元格字体颜色:", table.textColor);
            EditorGUILayout.PropertyField(cellBackground, new GUIContent("背景纹理:", "为Null时,则单元格没有背景"), true, null);
            table.FontSize = EditorGUILayout.IntField("单元格字号:", table.FontSize);

            if (GUILayout.Button("更新单元格信息", GUILayout.Width(150), GUILayout.Height(22)))
            {
                table.UpdateCell();
            }

            GUILayout.Space(20);

            EditorGUILayout.PropertyField(Rows, true, null);
            EditorGUILayout.PropertyField(cellObject, true, null);
            EditorGUILayout.PropertyField(rowObject, true, null);
            EditorGUILayout.PropertyField(rowParent, true, null);

            serializedObject.ApplyModifiedProperties();
        }
Beispiel #14
0
 public void RemoveCell(KGUI_TableCell cell)
 {
 }