using UnityEngine; using UnityEngine.UI; using System.Collections; using System.Collections.Generic; using System.Linq; namespace EasyLayout { /// /// EasyLayout compact layout. /// public static class EasyLayoutCompact { /// /// Group the specified uiElements. /// /// User interface elements. /// Base length (width or height). /// Layout. /// Result public static void Group(List uiElements, float baseLength, EasyLayout layout, List> group) { var length = baseLength; var spacing = (layout.Stacking==Stackings.Horizontal) ? layout.Spacing.x : layout.Spacing.y; var row = layout.GetRectTransformList(); for (int i = 0; i < uiElements.Count; i++) { var ui_length = layout.GetLength(uiElements[i]); if (row.Count == 0) { length -= ui_length; row.Add(uiElements[i]); continue; } if (length >= (ui_length + spacing)) { length -= ui_length + spacing; row.Add(uiElements[i]); } else { group.Add(row); length = baseLength; length -= ui_length; row = layout.GetRectTransformList(); row.Add(uiElements[i]); } } if (row.Count > 0) { group.Add(row); } } } }