Beispiel #1
0
        public void AddData(Vector2Int vector, string data)
        {
            KGUI_TableCell cell = GetTableCell(vector);

            if (cell == null)
            {
                return;
            }

            cell.SetCell(data);
        }
Beispiel #2
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 #3
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 #4
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();
        }