Esempio n. 1
0
        //if startPos = -1, it will keep the same position
        public void ChangeList(T[] infoList, int startPos = -1, bool resetContentPosition = false)
        {
            if (startPos == -1)
            {
                startPos = GetHighest().currentIndex;
            }

            mScrollRect.StopMovement();
            mScrollRect.content.anchoredPosition = Vector2.zero;

            var objs = objectPool.GetAllWithState(true);

            objs.ForEach(x => objectPool.Release(x));
            if (resetContentPosition)
            {
                mScrollRect.content.anchoredPosition = new Vector2((mIsHorizontal ? spacing : 0), (mIsVertical ? spacing : 0));
            }

            var totalSize          = 0f;
            var toCreate           = Mathf.Min(mInitialAmount, infoList.Length);
            var lastObjectPosition = Vector2.zero;

            for (var i = 0; i < toCreate; i++)
            {
                var obj = objectPool.Collect();
                obj.updateScrollObject(infoList[startPos + i], startPos + i);

                var rect = obj.GetComponent <RectTransform>();
                var posX = i > 0 ? lastObjectPosition.x + (mIsHorizontal ? +spacing : 0) : 0;
                var posY = i > 0 ? lastObjectPosition.y - (mIsVertical ? spacing : 0) : 0;
                rect.anchoredPosition = new Vector2(posX, posY);
                lastObjectPosition    = new Vector2(posX + (mIsHorizontal ? obj.currentWidth : 0), posY - (mIsVertical ? obj.currentHeight : 0));

                totalSize += (mIsVertical) ? obj.currentHeight : obj.currentWidth;
            }

            totalSize = (totalSize / (float)toCreate) * infoList.Length;
            bool canDrag = (mIsHorizontal && totalSize > mScrollRect.viewport.rect.width) || (mIsVertical && totalSize > mScrollRect.viewport.rect.height);

            ToggleScroll(canDrag);

            mInfoList = infoList;
        }
Esempio n. 2
0
        //if startIndex = -1, it will keep the same position
        public void ChangeList(T[] infoList, int startIndex = -1, bool resetContentPosition = false)
        {
            if (startIndex == -1)
            {
                startIndex = GetHighest().currentIndex;
            }

            mScrollRect.StopMovement();
            mScrollRect.content.anchoredPosition = Vector2.zero;

            var objs = objectPool.GetAllWithState(true);

            objs.ForEach(x => objectPool.Release(x));
            if (resetContentPosition)
            {
                mScrollRect.content.anchoredPosition = new Vector2((mIsHorizontal ? spacing : 0), (mIsVertical ? spacing : 0));
            }

            this.infoList = infoList;

            CreateList(startIndex);
        }