コード例 #1
0
    /// <summary>
    /// 强制重新刷新界面Item,保持原来的Item排版(如果Item数量有变更,必须传入Item数量)
    /// </summary>
    /// <param name="pItemCount"></param>
    public void ForceRefreshItem(int pItemCount = -1)
    {
        if (isNoneScrollView)
        {
            return;
        }
        if (pItemCount != -1)
        {
            itemCount = pItemCount;
        }
        if (childCount == 0)
        {
            MoveToItemByIndex(0);
            return;
        }
        DisableSpringPanel();
        MoveOverBoundsItemToCache();
        T tFirst = null;

        switch (movement)
        {
        case UIScrollView.Movement.Horizontal:
            tFirst = UIRecycleTableExtension.FindCustom <T, float>(itemControllers, x => x.itemTransform.localPosition.x, true);
            break;

        case UIScrollView.Movement.Vertical:
            tFirst = UIRecycleTableExtension.FindCustom <T, float>(itemControllers, x => x.itemTransform.localPosition.y, false);
            break;
        }
        if (tFirst == null)
        {
            return;
        }
        MoveAllItemToCache();
        var tBounds = tFirst.recycleTablInfo.bounds;

        tBounds.center += tFirst.itemTransform.localPosition;
        moveToItemByIndex(tFirst.recycleTablInfo.dataIndex, tBounds);
    }
コード例 #2
0
    /// <summary>
    /// Panel裁剪时触发
    /// </summary>
    /// <param name="pPanel"></param>
    protected void OnClipMove(UIPanel pPanel)
    {
        if (isNoneScrollView || itemCount == 0)
        {
            return;
        }

        var tPanelOffset      = Vector3.zero;
        var tAddItemDirection = CalculateAddItemDirection(out tPanelOffset);
        var tIsLeft           = tAddItemDirection == Direction.Left;
        var tIsBottom         = tAddItemDirection == Direction.Bottom;
        var tIsRight          = tAddItemDirection == Direction.Right;
        var tIsTop            = tAddItemDirection == Direction.Top;

        if (tIsLeft || tIsTop)
        {
            AddItem(tIsLeft ? Direction.Left : tIsTop?Direction.Top: Direction.None);

            var tIsTopOrLeft   = false;
            var tFirstItemCtrl = UIRecycleTableExtension.Find(itemControllers, x => x.recycleTablInfo.dataIndex == 0);
            var tFirstBounds   = new Bounds();
            if (tFirstItemCtrl != null)
            {
                tFirstBounds         = tFirstItemCtrl.recycleTablInfo.bounds;
                tFirstBounds.center += tFirstItemCtrl.itemTransform.localPosition + scrollViewTrans.localPosition;
                tIsTopOrLeft         = tIsLeft ? tFirstBounds.min.x > panelBounds.min.x : tIsTop ? tFirstBounds.max.y < panelBounds.max.y : tIsTopOrLeft;
            }

            var tInfo = new RecycleTableDragInfo <T>()
            {
                restrictScrollView = tIsTopOrLeft,
                panelOffset        = tPanelOffset,
                dragDirection      = Direction.Top | Direction.Left,
                instant            = false,
                movement           = movement,
            };

            if (scrollView.isDragging)
            {
                dragInfo = tInfo;
                if (!tIsTopOrLeft)
                {
                    MoveOverBoundsItemToCache();
                }
            }
            else if (tIsTopOrLeft)
            {
                RestrictWithinBounds(tInfo);
            }
            else
            {
                MoveOverBoundsItemToCache(false);
            }
        }
        else if (tIsRight || tIsBottom)
        {
            AddItem(tIsRight ? Direction.Right : tIsBottom?Direction.Bottom: Direction.None);

            var tIsBottomOrRight = false;
            var tLastItemCtrl    = UIRecycleTableExtension.Find(itemControllers, x => x.recycleTablInfo.dataIndex == itemCount - 1);
            var tLastBounds      = new Bounds();
            if (tLastItemCtrl != null)
            {
                tLastBounds         = tLastItemCtrl.recycleTablInfo.bounds;
                tLastBounds.center += tLastItemCtrl.itemTransform.localPosition + scrollViewTrans.localPosition;
                tIsBottomOrRight    = tIsRight ? tLastBounds.max.x <panelBounds.max.x : tIsBottom?tLastBounds.min.y> panelBounds.min.y : tIsBottomOrRight;
            }

            var tInfo = new RecycleTableDragInfo <T>()
            {
                restrictScrollView = tIsBottomOrRight,
                panelOffset        = tPanelOffset,
                dragDirection      = Direction.Bottom | Direction.Right,
                instant            = false,
                movement           = movement,
            };

            if (scrollView.isDragging)
            {
                dragInfo = tInfo;
                if (!tIsBottomOrRight)
                {
                    MoveOverBoundsItemToCache();
                }
            }
            else if (tIsBottomOrRight)
            {
                RestrictWithinBounds(tInfo);
            }
            else
            {
                MoveOverBoundsItemToCache(false);
            }
        }
    }
コード例 #3
0
    /// <summary>
    /// 添加Item
    /// </summary>
    /// <param name="pDirection"></param>
    protected void AddItem(Direction pDirection)
    {
        if (pDirection == Direction.None)
        {
            return;
        }
        if (itemControllers == null || itemControllers.Count == 0)
        {
            return;
        }
        T   tTempItemCtrl = null;
        var tDataIndex    = 0;

        switch (pDirection)
        {
        case Direction.Right:
        case Direction.Bottom:
            tTempItemCtrl = UIRecycleTableExtension.FindCustom <T, float>(itemControllers, x => x.recycleTablInfo.dataIndex, false);
            tDataIndex    = tTempItemCtrl.recycleTablInfo.dataIndex + 1;
            if (tDataIndex >= itemCount)
            {
                return;
            }
            break;

        case Direction.Left:
        case Direction.Top:
            tTempItemCtrl = UIRecycleTableExtension.FindCustom <T, float>(itemControllers, x => x.recycleTablInfo.dataIndex, true);
            tDataIndex    = tTempItemCtrl.recycleTablInfo.dataIndex - 1;
            if (tDataIndex < 0)
            {
                return;
            }
            break;
        }
        if (tTempItemCtrl == null)
        {
            return;
        }
        var tItemCtrl = GetItemControllerByCache(tDataIndex);

        onUpdateItem(tItemCtrl, tDataIndex);

        var tTempItemBounds = NGUIMath.CalculateRelativeWidgetBounds(tTempItemCtrl.itemTransform);

        tTempItemBounds.center += tTempItemCtrl.itemTransform.localPosition;

        var tItemBounds = NGUIMath.CalculateRelativeWidgetBounds(tItemCtrl.itemTransform);
        var tInfo       = tItemCtrl.recycleTablInfo;

        tInfo.bounds = tItemBounds;
        tItemCtrl.recycleTablInfo = tInfo;

        var tItemOffset = 0F;

        switch (pDirection)
        {
        case Direction.Left:
        case Direction.Bottom:
            switch (movement)
            {
            case UIScrollView.Movement.Horizontal:
                tItemOffset = tTempItemBounds.min.x - tItemBounds.max.x - itemIntervalPixel;
                break;

            case UIScrollView.Movement.Vertical:
                tItemOffset = tTempItemBounds.min.y - tItemBounds.max.y - itemIntervalPixel;
                break;
            }
            break;

        case Direction.Right:
        case Direction.Top:
            switch (movement)
            {
            case UIScrollView.Movement.Horizontal:
                tItemOffset = tTempItemBounds.max.x - tItemBounds.min.x + itemIntervalPixel;
                break;

            case UIScrollView.Movement.Vertical:
                tItemOffset = tTempItemBounds.max.y - tItemBounds.min.y + itemIntervalPixel;
                break;
            }
            break;
        }
        switch (movement)
        {
        case UIScrollView.Movement.Horizontal:
            tItemCtrl.itemTransform.SetLocalPos(tItemOffset, 0);
            break;

        case UIScrollView.Movement.Vertical:
            tItemCtrl.itemTransform.SetLocalPos(0, tItemOffset);
            break;
        }

        mCalculatedBounds = true;
    }