/// <summary> /// Calculates the size of the box layout container. /// </summary> /// <param name="obj">The container to lay out.</param> /// <param name="args">The parameters to use for layout.</param> /// <param name="direction">The direction which is being calculated.</param> /// <returns>The minimum and preferred box layout size.</returns> private static LayoutResults Calc(GameObject obj, BoxLayoutParams args, PanelDirection direction) { var transform = obj.AddOrGet <RectTransform>(); int n = transform.childCount; var result = new LayoutResults(direction, n); var components = ListPool <ILayoutElement, BoxLayoutGroup> .Allocate(); for (int i = 0; i < n; i++) { var child = transform.GetChild(i)?.gameObject; if (child != null && child.activeInHierarchy) { // Only on active game objects components.Clear(); child.GetComponents(components); var hc = PUIUtils.GetSize(child, direction, components); if (args.Direction == direction) { result.Accum(hc, args.Spacing); } else { result.Expand(hc); } result.children.Add(hc); } } components.Recycle(); return(result); }