/// <summary> /// Cleans the last Grid. /// </summary> public void CleanGrid() { if (_verticalGrids != null) { foreach (GameObject go in _verticalGrids) { Destroy(go); } } _horizontalGridPrefab.CalculateLayoutInputHorizontal(); _heightMode = HeightMode.Empty; _widthMode = WidthMode.Empty; }
/// <summary> /// Best Fit of column width its proportional to amount of text in that particular column. /// </summary> private void BestFitColumnWidth() { _horizontalGridPrefab.FitX = false; _horizontalGridPrefab.UniqueX = true; int i = 0; foreach (GameObject go in _verticalGrids) { GridLayout grid = go.GetComponent <GridLayout>(); RectTransform rect = grid.GetComponent <RectTransform>(); rect.sizeDelta = new Vector2(Mathf.Min(_avgLenghtWords[i] * 20f + 50, 350f), grid.CellSize.y); grid.CalculateLayoutInputHorizontal(); i++; } _horizontalGridPrefab.CalculateLayoutInputHorizontal(); }
/// <summary> /// Adjust Spacing of grid. /// </summary> private void AdjustRowSpacing() { _Spacing = Spacing; foreach (GameObject go in _verticalGrids) { GridLayout grid = go.GetComponent <GridLayout>(); grid.FitY = false; grid.Spacing = new Vector2(grid.Spacing.x, Spacing.y); grid.CalculateLayoutInputHorizontal(); } if (Spacing.x < 0) { Spacing.x = 0; } _horizontalGridPrefab.Spacing = new Vector2(Spacing.x, _horizontalGridPrefab.Spacing.y); _horizontalGridPrefab.CalculateLayoutInputHorizontal(); }
/// <summary> /// Sets the rows Heights to a homogeneous value. /// </summary> /// <param name="val"></param> private void SetHomogeneousRowHeight(bool val) { foreach (GameObject go in _verticalGrids) { GridLayout grid = go.GetComponent <GridLayout>(); grid.UniqueY = false; } _horizontalGridPrefab.UniqueX = false; FixedHeight = _horizontalGridPrefab.CellSize.y; for (int j = 0; j < _verticalGrids.Count; j++) { GridLayout verticalGrid = _verticalGrids[j].GetComponent <GridLayout>(); verticalGrid.FitY = val; verticalGrid.CalculateLayoutInputHorizontal(); } _horizontalGridPrefab.FitY = val; _horizontalGridPrefab.CalculateLayoutInputHorizontal(); }
/// <summary> /// Best Fit Height its proportional to amount of thext in that particular row. /// </summary> private void BestFitRowsHeight() { _horizontalGridPrefab.FitY = false; foreach (GameObject go in _verticalGrids) { GridLayout grid = go.GetComponent <GridLayout>(); grid.UniqueY = true; if (_showingRows >= 0 && _showingRows <= _gridOfTextElements.Count) { for (int i = 1; i < _gridOfTextElements.Count; i++) { List <GameObject> row = _gridOfTextElements[i]; foreach (GameObject rowElement in row) { RectTransform rect = rowElement.GetComponent <RectTransform>(); rect.sizeDelta = new Vector2(grid.CellSize.x, Mathf.Min(_avgLenghtRow[i] * 13f, 200f)); } } } grid.CalculateLayoutInputHorizontal(); } _horizontalGridPrefab.CalculateLayoutInputHorizontal(); }
/// <summary> /// Sets the columns and/or height to a Fixed Value exposed in the editor. /// </summary> private void SetFixedValues() { foreach (GameObject go in _verticalGrids) { GridLayout grid = go.GetComponent <GridLayout>(); grid.UniqueY = false; } _horizontalGridPrefab.UniqueX = false; if (HeightMode == HeightMode.Fix) { _horizontalGridPrefab.FitY = false; if (WidthMode == WidthMode.Fix) { _horizontalGridPrefab.FitX = false; _horizontalGridPrefab.CellSize = new Vector2(FixedWidth, FixedHeight); } else { _horizontalGridPrefab.FitX = true; _horizontalGridPrefab.CellSize = new Vector2(_horizontalGridPrefab.CellSize.x, FixedHeight); } foreach (GameObject go in _verticalGrids) { GridLayout grid = go.GetComponent <GridLayout>(); grid.CalculateLayoutInputHorizontal(); } } else if (WidthMode == WidthMode.Fix) { _horizontalGridPrefab.FitX = false; _horizontalGridPrefab.FitY = true; _horizontalGridPrefab.CellSize = new Vector2(FixedWidth, _horizontalGridPrefab.CellSize.y); } _horizontalGridPrefab.CalculateLayoutInputHorizontal(); Canvas.ForceUpdateCanvases(); _horizontalGridPrefab.SetLayoutVertical(); }