public float GetMinSize(RectTransform rect, int axis)
 {
     if (axis == 0)
     {
         return(LayoutUtility.GetMinWidth(rect));
     }
     return(LayoutUtility.GetMinHeight(rect));
 }
예제 #2
0
        //------------------------------------------------------------------------------------------------------
        public override void CalculateLayoutInputVertical()
        {
            int columns = GetColumnCount();
            int rows    = GetRowCount();

            // Calc it based on all cells in that column
            // Cycle through all cells and store max values for column
            rowMinHeights       = new float[rows];
            rowPreferredHeights = new float[rows];
//			rowFlexibleHeights = new float[rows];
            for (int r = 0; r < rows; r++)
            {
                rowMinHeights [r]       = 0;
                rowPreferredHeights [r] = 0;
//				rowFlexibleHeights [r] = 0;
            }

            for (int i = 0; i < rectChildren.Count; i++)
            {
                var child = rectChildren [i];
                int row   = GetCellRow(i, columns, rows);
                rowMinHeights[row]       = Mathf.Max(rowMinHeights[row], LayoutUtility.GetMinHeight(child));
                rowPreferredHeights[row] = Mathf.Max(rowPreferredHeights[row], LayoutUtility.GetPreferredHeight(child));
//				rowFlexibleHeights[row] = Mathf.Max (rowFlexibleHeights[row], LayoutUtility.GetFlexibleHeight (child));
            }

            float totalMinHeight       = padding.vertical;
            float totalPreferredHeight = padding.vertical;

            //			float totalFlexibleHeight = 0;
            for (int r = 0; r < rows; r++)
            {
                totalMinHeight       += rowMinHeights [r] + spacing.y;
                totalPreferredHeight += rowPreferredHeights [r] + spacing.y;
                //				totalFlexibleHeight += rowFlexibleHeights [r] + spacing.y;
            }
            totalMinHeight       -= spacing.y;
            totalPreferredHeight -= spacing.y;
            //			totalFlexibleHeight -= spacing.y;

            SetLayoutInputForAxis(totalMinHeight, totalPreferredHeight, -1, 1);

            float prefH      = LayoutUtility.GetPreferredHeight(rectTransform);
            float extraSpace = prefH - totalPreferredHeight;

            // Stretch if there is a layout element specifying extra space
            if (extraSpace > 0)
            {
                // Give extra space equally
                for (int r = 0; r < rows; r++)
                {
                    rowPreferredHeights [r] += extraSpace / rows;
                }
            }
        }
예제 #3
0
        public static float GetMinSize(RectTransform rect, int axis)
        {
            float result;

            if (axis == 0)
            {
                result = LayoutUtility.GetMinWidth(rect);
            }
            else
            {
                result = LayoutUtility.GetMinHeight(rect);
            }
            return(result);
        }