From 81dd26b5ef292fb9450009d7e80c51e9f352ae22 Mon Sep 17 00:00:00 2001 From: Rahul Raman Date: Tue, 27 Dec 2016 20:16:50 +0000 Subject: [PATCH] Edited SetLayoutVertical() to avoid unnecessary recomputation of maxPreferredHeightInRow --HG-- branch : develop_5.3 --- Scripts/Layout/TableLayoutGroup.cs | 31 ++++++++++-------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/Scripts/Layout/TableLayoutGroup.cs b/Scripts/Layout/TableLayoutGroup.cs index 4ee3be7..b48d6b4 100644 --- a/Scripts/Layout/TableLayoutGroup.cs +++ b/Scripts/Layout/TableLayoutGroup.cs @@ -6,7 +6,7 @@ namespace UnityEngine.UI.Extensions /// /// Arranges child objects into a non-uniform grid, with fixed column widths and flexible row heights /// - public class TableLayout : LayoutGroup + public class TableLayoutGroup : LayoutGroup { public enum Corner { @@ -190,6 +190,8 @@ namespace UnityEngine.UI.Extensions float requiredHeightWithoutPadding = 0; + float[] maxPreferredHeightInRows = new float[rowCount]; + for (int i = 0; i < rowCount; i++) { float maxPreferredHeightInRow = 0; @@ -205,6 +207,7 @@ namespace UnityEngine.UI.Extensions } maxPreferredHeightInRow = Mathf.Max(minimumRowHeight, maxPreferredHeightInRow); + maxPreferredHeightInRows[i] = maxPreferredHeightInRow; requiredHeightWithoutPadding += maxPreferredHeightInRow; requiredHeightWithoutPadding += rowSpacing; } @@ -225,7 +228,10 @@ namespace UnityEngine.UI.Extensions { float positionX = startOffset.x; - float maxPreferredHeightInRow = 0; + float sizeYOfRect = maxPreferredHeightInRows[i] + rowSpacing; + + if (cornerY == 1) + positionY -= sizeYOfRect; for (int j = 0; j < columnCount; j++) { @@ -240,29 +246,12 @@ namespace UnityEngine.UI.Extensions positionX -= sizeXOfRect; SetChildAlongAxis(rectChildren[childIndex], 0, positionX, columnWidths[j]); + SetChildAlongAxis(rectChildren[childIndex], 1, positionY, maxPreferredHeightInRows[i]); if (cornerX != 1) positionX += sizeXOfRect; - - maxPreferredHeightInRow = Mathf.Max(LayoutUtility.GetPreferredHeight(rectChildren[childIndex]), maxPreferredHeightInRow); } - - maxPreferredHeightInRow = Mathf.Max(minimumRowHeight, maxPreferredHeightInRow); - float sizeYOfRect = maxPreferredHeightInRow + rowSpacing; - - if (cornerY == 1) - positionY -= sizeYOfRect; - - for (int j = 0; j < columnCount; j++) - { - int childIndex = (i * columnCount) + j; - - if (childIndex >= rectChildren.Count) - break; - - SetChildAlongAxis(rectChildren[childIndex], 1, positionY, maxPreferredHeightInRow); - } - + if (cornerY != 1) positionY += sizeYOfRect; }