private void CreatCell(int i, KGUI_TableRow row, ref float rowX, int j) { var cell = Instantiate(cellObject, row.transform); cell.name = "cell" + j; var kguiCell = cell.GetComponent <KGUI_TableCell>(); //设置瞄点 kguiCell.rectTransform.anchorMin = new Vector2(0, 1); kguiCell.rectTransform.anchorMax = new Vector2(0, 1); kguiCell.rectTransform.pivot = new Vector2(0, 1); kguiCell.SetCell("小样"); kguiCell.UpdateCell(textColor, cellBackground, FontSize); //计算坐标 cell.transform.localPosition = new Vector3(rowX, 0, 0); //计算下一个单元格的坐标 rowX += cellSize.x + spacing; //设置单元格大小 kguiCell.SetSize(cellSize); kguiCell.Position = new Vector2Int(i, j);//ID坐标 row.Add(kguiCell); }
///// <summary> ///// 合并 ///// </summary> //public void OnMerge(KGUI_TableCell startCell, KGUI_TableCell endCell) //{ // //检查是否在相邻 // startCell.OnMerge(endCell, spacing); //} /// <summary> /// 根据坐标获取到单元格 /// </summary> /// <param name="position"></param> /// <returns></returns> public KGUI_TableCell GetTableCell(Vector2Int position) { if (position.x >= Rows.Count) { return(null); } //获取都行 KGUI_TableRow row = Rows[position.x]; if (position.y >= row.Cells.Count) { return(null); } return(row.Cells[position.y]); }