Esempio n. 1
0
        /// <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();
        }
Esempio n. 2
0
        /// <summary>
        /// Computes vertical sizes for the components in this relative layout.
        /// </summary>
        /// <param name="children">The location to store information about these components.</param>
        internal static void CalcY(this ICollection <RelativeLayoutResults> children)
        {
            var comps = ListPool <Component, RelativeLayout> .Allocate();

            foreach (var ip in children)
            {
                var child        = ip.Transform.gameObject;
                var overrideSize = ip.OverrideSize;
                comps.Clear();
                // Calculate the preferred size using all layout components
                child.gameObject.GetComponents(comps);
                float h = PUIUtils.CalcSizes(child, PanelDirection.Vertical, comps).preferred;
                // Set override size by axis if necessary
                if (overrideSize.y > 0.0f)
                {
                    h = overrideSize.y;
                }
                ip.PreferredHeight = h;
            }
            comps.Recycle();
        }