コード例 #1
0
        void NeatlyItems()
        {
            ScrollableListItem prevItem = null;
            var totalItemHeight         = 0f;
            var index = 0;
            var items = GetItems();

            foreach (var item in items)
            {
                var itemPaddingBottom = index == items.Length  ? 0f : item.padding.Bottom;
                var itemHeight        = item.GetComponent <RectTransform> ().rect.height + itemPaddingBottom;
                if (prevItem != null)
                {
                    var nextPosition = prevItem.transform.position - new Vector3(0f, itemHeight, 0f);
                    item.transform.position = nextPosition;
                }
                prevItem         = item;
                totalItemHeight += itemHeight;
                ++index;
            }
            _rectTrans.SetHeight(totalItemHeight);
        }
コード例 #2
0
        void HorizontalNeatlyItems()
        {
            ScrollableListItem prevItem = null;
            var totalItemWidth          = 0f;
            var index = 0;
            var items = GetItems();

            foreach (var item in items)
            {
                var itemPaddingRight = index == items.Length  ? 0f : item.padding.Right + padding.Right;
                var itemWidth        = item.GetComponent <RectTransform> ().rect.width + itemPaddingRight;
                if (prevItem != null)
                {
                    var nextPosition = prevItem.transform.position + new Vector3(itemWidth, 0f, 0f);
                    item.transform.position = nextPosition;
                }
                prevItem        = item;
                totalItemWidth += itemWidth;
                ++index;
            }
            _rectTrans.SetWidth(totalItemWidth);
        }