/// <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));//重新计算出总高度 }
/// <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; } } }