Beispiel #1
0
        protected virtual float CalculateAnotherAxisPreferredSize(bool isVertical)
        {
            var anotherAxis = isVertical ? 0 : 1;
            List <GameObject> visibleElements = new List <GameObject>();

            for (int i = _cachedMinMaxIndex.x; i <= _cachedMinMaxIndex.y; i++)
            {
                var elementRectTransform = i >= 0 && m_elements.Count > i && m_elements[i] != null ? m_elements[i].transform as RectTransform : null;
                if (elementRectTransform != null)
                {
                    _layoutSize[anotherAxis] = Mathf.Max(_layoutSize[anotherAxis], LayoutUtilityEx.GetPreferredSize(elementRectTransform, anotherAxis));
                }
            }
            return(_layoutSize[anotherAxis]);
        }
Beispiel #2
0
        protected override void Reload(GameObject p_obj, int p_indexReload)
        {
            if (p_obj == null)
            {
                return;
            }

            //Unregister or Register Index
            if (Application.isPlaying)
            {
                if (p_indexReload < _cachedMinMaxIndex.x || p_indexReload > _cachedMinMaxIndex.y)
                {
                    UnregisterVisibleElement(p_indexReload);
                }
                else
                {
                    RegisterVisibleElement(p_indexReload);
                }
                if (Application.isEditor)
                {
                    p_obj.transform.name = "[" + p_indexReload + "] " + System.Text.RegularExpressions.Regex.Replace(p_obj.transform.name, @"^\[[0-9]+\] ", "");
                }
            }

            Vector3 v_elementPosition = GetElementPosition(p_indexReload);

            p_obj.transform.localPosition = v_elementPosition;

            var v_fitter = p_obj.GetComponent <ContentSizeFitter>();

            if (v_fitter != null)
            {
                v_fitter.enabled = false;
            }
            //Recalculate Item Size
            if (Content != null)
            {
                RectTransform v_rectTransform = p_obj.transform as RectTransform;
                float         v_itemSize      = GetCachedElementSize(p_indexReload);
                if (v_rectTransform != null)
                {
                    //var v_layout = v_rectTransform.GetComponent<LayoutElement>();
                    v_rectTransform.pivot = Content.pivot;
                    if (IsVertical())
                    {
                        _layoutSize.x = Mathf.Max(_layoutSize.x, LayoutUtilityEx.GetPreferredWidth(v_rectTransform));
                        if (Mathf.Abs(GetLocalHeight(v_rectTransform) - v_itemSize) > SIZE_ERROR)
                        {
                            SetLocalHeight(v_rectTransform, v_itemSize);
                        }

                        //SetLayoutElementPreferredSize(v_layout, new Vector2(-1, v_itemSize));

                        //Apply Padding Horizontal
                        var v_width = GetLocalWidth(Content) - (m_padding.left + m_padding.right);
                        if (Mathf.Abs(GetLocalWidth(v_rectTransform) - v_width) > SIZE_ERROR)
                        {
                            SetLocalWidth(v_rectTransform, v_width);
                        }
                    }
                    else
                    {
                        _layoutSize.y = Mathf.Max(_layoutSize.y, LayoutUtilityEx.GetPreferredHeight(v_rectTransform));
                        if (Mathf.Abs(GetLocalWidth(v_rectTransform) - v_itemSize) > SIZE_ERROR)
                        {
                            SetLocalWidth(v_rectTransform, v_itemSize);
                        }

                        //SetLayoutElementPreferredSize(v_layout, new Vector2(v_itemSize, -1));

                        //Apply Padding Vertical
                        var v_height = GetLocalHeight(Content) - (m_padding.top + m_padding.bottom);
                        if (Mathf.Abs(GetLocalHeight(v_rectTransform) - v_height) > SIZE_ERROR)
                        {
                            SetLocalHeight(v_rectTransform, v_height);
                        }
                    }
                }
            }

            if (v_fitter != null)
            {
                v_fitter.enabled = true;
            }
        }