/// <summary>
            /// Calculates the size of the item.
            /// </summary>
            /// <param name="reset">Reset item size.</param>
            /// <returns>Item size.</returns>
            public virtual Vector2 GetItemSize(bool reset = false)
            {
                Owner.DefaultItem.gameObject.SetActive(true);

                var rt = Owner.DefaultItem.transform as RectTransform;

                Owner.LayoutElements.Clear();
                Compatibility.GetComponents <ILayoutElement>(Owner.DefaultItem.gameObject, Owner.LayoutElements);
                Owner.LayoutElements.Sort((x, y) => - x.layoutPriority.CompareTo(y.layoutPriority));

                var size = Owner.ItemSize;

                if ((size.x == 0f) || reset)
                {
                    size.x = Mathf.Max(PreferredWidth(Owner.LayoutElements), rt.rect.width, 1f);
                    if (float.IsNaN(size.x))
                    {
                        size.x = 1f;
                    }
                }

                if ((size.y == 0f) || reset)
                {
                    size.y = Mathf.Max(PreferredHeight(Owner.LayoutElements), rt.rect.height, 1f);
                    if (float.IsNaN(size.y))
                    {
                        size.y = 1f;
                    }
                }

                Owner.DefaultItem.gameObject.SetActive(false);

                return(size);
            }
Beispiel #2
0
        /// <summary>
        /// Calculates the size of the item.
        /// </summary>
        protected override void CalculateItemSize()
        {
            var rect            = DefaultItem.transform as RectTransform;
            var layout_elements = new List <ILayoutElement>();

            Compatibility.GetComponents <ILayoutElement>(DefaultItem.gameObject, layout_elements);

            if (ItemSize.y == 0)
            {
                ItemSize.y = Mathf.Max(PreferredHeight(layout_elements), rect.rect.height);
            }

            if (ItemSize.x == 0)
            {
                ItemSize.x = Mathf.Max(PreferredWidth(layout_elements), rect.rect.width);
            }
        }