/// <summary> /// Initializes and computes horizontal sizes for the components in this relative /// layout. /// </summary> /// <param name="children">The location to store information about these components.</param> /// <param name="all">The components to lay out.</param> /// <param name="constraints">The constraints defined for these components.</param> internal static void CalcX(this ICollection <RelativeLayoutResults> children, RectTransform all, IDictionary <GameObject, RelativeLayoutParams> constraints) { var comps = ListPool <Component, RelativeLayoutGroup> .Allocate(); var paramMap = DictionaryPool <GameObject, RelativeLayoutResults, RelativeLayoutGroup> .Allocate(); int n = all.childCount; children.Clear(); for (int i = 0; i < n; i++) { var child = all.GetChild(i)?.gameObject; if (child != null) { comps.Clear(); // Calculate the preferred size using all layout components child.GetComponents(comps); var horiz = PUIUtils.CalcSizes(child, PanelDirection.Horizontal, comps); if (!horiz.ignore) { RelativeLayoutResults ip; float w = horiz.preferred; if (constraints.TryGetValue(child, out RelativeLayoutParams cons)) { ip = new RelativeLayoutResults(child.rectTransform(), cons); // Set override size by axis if necessary var overrideSize = ip.OverrideSize; if (overrideSize.x > 0.0f) { w = overrideSize.x; } paramMap[child] = ip; } else { // Default its layout to fill all ip = new RelativeLayoutResults(child.rectTransform(), null); } ip.PreferredWidth = w; children.Add(ip); } } } // Resolve object references to other children foreach (var ip in children) { ip.TopParams = InitResolve(ip.TopEdge, paramMap); ip.BottomParams = InitResolve(ip.BottomEdge, paramMap); ip.LeftParams = InitResolve(ip.LeftEdge, paramMap); ip.RightParams = InitResolve(ip.RightEdge, paramMap); // All of these will die simultaneously when the list is recycled } paramMap.Recycle(); comps.Recycle(); }
/// <summary> /// Resolves a component reference if needed. /// </summary> /// <param name="edge">The edge to resolve.</param> /// <param name="lookup">The location where the component can be looked up.</param> /// <returns>The linked parameters for that edge if needed.</returns> private static RelativeLayoutResults InitResolve(EdgeStatus edge, IDictionary <GameObject, RelativeLayoutResults> lookup) { RelativeLayoutResults result = null; if (edge.Constraint == RelativeConstraintType.ToComponent) { if (!lookup.TryGetValue(edge.FromComponent, out result)) { edge.Constraint = RelativeConstraintType.Unconstrained; } } return(result); }