예제 #1
0
    /// <summary>
    /// 自动调整多出的那个项的位置
    /// </summary>
    protected virtual void AutoSetItemState()
    {
        LoopTime = 0;  //防止While循环条件一直成立导致导致死循环
        RectTransform lastItem  = ContentRectrans.GetChildEX(ContentRectrans.childCount - 1);
        RectTransform firstItem = ContentRectrans.GetChildEX(0);

        if (Direction == LoopViewShowDirection.Up)
        {
            //**检查最后一个项是否可见    如果不可见则移动到顶部
            while (LoopTime < ContentRectrans.childCount && IsItemVisible(lastItem) == false && IsItemVisible(firstItem))
            {
                ScrollUpDirection(lastItem, firstItem);
                firstItem = ContentRectrans.GetChildEX(0);
                lastItem  = ContentRectrans.GetChildEX(ContentRectrans.childCount - 1);
                ++LoopTime;
            }//由于快读滑动时候可能一下子滑出超过多个Item项的距离
        }
        else
        {
            //***检测第一个项是否可见 如果不可见则移动到末尾
            while (LoopTime < ContentRectrans.childCount && IsItemVisible(firstItem) == false && IsItemVisible(lastItem))
            {
                ScrollDownDirection(firstItem, lastItem);
                lastItem  = ContentRectrans.GetChildEX(ContentRectrans.childCount - 1);
                firstItem = ContentRectrans.GetChildEX(0);
                ++LoopTime;
            }
        }
    }
    /// <summary>
    /// 自动调整多出的那个项的位置
    /// </summary>
    protected virtual void AutoSetItemState()
    {
        LoopTime = 0;
        RectTransform lastItem  = ContentRectrans.GetChildEX(ContentRectrans.childCount - 1);
        RectTransform firstItem = ContentRectrans.GetChildEX(0);

        if (Direction == LoopViewShowDirection.Left)
        {
            //***如果第一个项可见且最后一个项不可见 则移动最后一个到第一个
            while (LoopTime < ContentRectrans.childCount && IsItemVisible(firstItem) && IsItemVisible(lastItem) == false)
            {
                ScrollLeftDirection(lastItem, firstItem);
                lastItem  = ContentRectrans.GetChildEX(ContentRectrans.childCount - 1);
                firstItem = ContentRectrans.GetChildEX(0);
                ++LoopTime;
            }
        }
        else
        {
            //**如果最后一个项可见且第一一个项不可见 则移动第一个到最后以个
            while (LoopTime < ContentRectrans.childCount && IsItemVisible(lastItem) && IsItemVisible(firstItem) == false)
            {
                ScrollRightDirection(firstItem, lastItem);
                lastItem  = ContentRectrans.GetChildEX(ContentRectrans.childCount - 1);
                firstItem = ContentRectrans.GetChildEX(0);
                ++LoopTime;
            }//由于快读滑动时候可能一下子滑出超过多个Item项的距离 所以这里是一个while 循环
        }
    }
예제 #3
0
    public virtual void RollView(LoopViewShowDirection direction, float endPosX, float tweenTime, bool isAbsDistance = false, System.Action completeRoll = null)
    {
        if (direction == LoopViewShowDirection.None || (int)direction < (int)LoopViewShowDirection.Left)
        {
            Debug.LogError("RollViewEx  Fail,direction= " + direction);
            return;
        }

        if (IsScrolling)
        {
            return;
        }
        if (isAbsDistance == false)
        {
            endPosX += ContentRectrans.anchoredPosition.x;
        }

        #region 检测数值  避免由于滑动的太远太快导致视图显示异常 2019/4/23 新增
        float offset = endPosX - ContentRectrans.anchoredPosition.x;
        if (Mathf.Abs(offset) / tweenTime * Time.deltaTime >= ViewRectHalfSize)
        {
            Debug.LogError("滑动的距离太远且时间太短 导致视图异常 " + offset);
            return;
        }
        #endregion


        if (CheckContentOffsetAvailable(direction, endPosX) == false)
        {
            return;
        }

        RollView(direction);
        if (ContentRectrans.anchoredPosition.x == endPosX)
        {
            UpdateItemState();
            OnCompleteScrollView();
            return;
        }
        OnBeginScrollView();
        if (completeRoll != null)
        {
            ContentRectrans.DOAnchorPosX(endPosX, tweenTime).OnUpdate(UpdateItemState).OnComplete(() =>
            {
                OnCompleteScrollView();
                if (completeRoll != null)
                {
                    completeRoll.Invoke();
                }
            }).SetEase(mTweenAnimationCurve);
        }
        else
        {
            ContentRectrans.DOAnchorPosX(endPosX, tweenTime).OnUpdate(UpdateItemState).OnComplete(OnCompleteScrollView).SetEase(mTweenAnimationCurve);
        }
    }
예제 #4
0
    /// <summary>
    /// 自动吸附到最近的一个整数节点位置
    /// </summary>
    protected void AutoAdsorbentItem()
    {
        if (IsAdsobent == false || ContentRectrans.anchoredPosition.x == 0)
        {
            OnCompleteScrollView();  //为下一次滑动做准备
            AutoSetItemState();
            return;
        }
        float distancePositionX = 0;

        float offsetItemDistance = 0, offset = 0;

        offsetItemDistance = Mathf.FloorToInt(ContentRectrans.anchoredPosition.x / ItemDistance);  //偏移多少个位置,注意负数时候的取整
        offset             = (ContentRectrans.anchoredPosition.x) % ItemDistance;


        distancePositionX = offsetItemDistance * ItemDistance;
        if (ContentRectrans.anchoredPosition.x > 0)
        {
            Direction = LoopViewShowDirection.Left;//这里赋值是为了动画处理完成后的AutoSetItemState
            if (Mathf.Abs(offset) > HalfItemDistance)
            {
                distancePositionX += ItemDistance;
            }
            //Debug.Log("Left " + offsetItemDistance);
        }
        else
        {
            Direction = LoopViewShowDirection.Right;
            if (Mathf.Abs(offset) < HalfItemDistance)
            {
                distancePositionX += ItemDistance;  //由于负数FloorToInt是向下取整的,所以这里要特殊处理
            }
            //    Debug.Log("Right " + offsetItemDistance);
        }

        if (OnItemMovingAct == null)
        {
            ContentRectrans.DOAnchorPosX(distancePositionX, Time.unscaledDeltaTime * 5).OnComplete(OnCompleteAsdobent);
        }
        else
        {
            ContentRectrans.DOAnchorPosX(distancePositionX, Time.unscaledDeltaTime * 5).OnComplete(OnCompleteAsdobent).OnUpdate(OnContentViewTweenUpdate);
        }
    }
예제 #5
0
    public override void RollView(LoopViewShowDirection direction, float endPosx, float tweenTime, bool isAbsDistance, System.Action completeRoll = null)
    {
        if (direction == LoopViewShowDirection.None || (int)direction < (int)LoopViewShowDirection.Left)
        {
            Debug.LogError("RollViewEx  Fail,direction= " + direction);
            return;
        }

        if (IsScrolling)
        {
            return;
        }
        ContentViewShowDirection = direction;

        if (isAbsDistance == false)
        {
            endPosx += ContentRectrans.anchoredPosition.x;
        }

        if (CheckContentOffsetAvailable(direction, endPosx) == false)
        {
            return;
        }

        //        Debug.Log("------------" + endPosx + "  " + direction);
        if (IsLoopCircleModel)
        {
            #region 可以循环滑动
            RollView(direction);
            if (ContentRectrans.anchoredPosition.x == endPosx)
            {
                UpdateItemState();
                OnCompleteScrollView();
                return;
            }
            OnBeginScrollView();
            if (completeRoll == null)
            {
                MoveTweenner = ContentRectrans.DOAnchorPosX(endPosx, tweenTime).OnUpdate(OnUpdateTweenView).OnComplete(OnCompleteScrollView).SetEase(mTweenAnimationCurve);
            }
            else
            {
                MoveTweenner = ContentRectrans.DOAnchorPosX(endPosx, tweenTime).OnUpdate(OnUpdateTweenView).OnComplete(() =>
                {
                    OnCompleteScrollView();
                    completeRoll();
                }).SetEase(mTweenAnimationCurve);
            }
            #endregion

            return;
        }

        #region 数据不足以循环时候只显示一页

        float maxOffset = CaculateMaxOffsetDistance(direction);
        //   Debug.Log("maxOffset=" + maxOffset);

        if (mLastRecordContentAnchoePos.x == ContentInitialedPos.x + maxOffset)
        {
            if (completeRoll != null)
            {
                completeRoll.Invoke();
            }
            return; //已经达到边界
        }
        float realEndPosx = 0;

        if (Mathf.Abs(endPosx) < Mathf.Abs(maxOffset))
        {
            realEndPosx = endPosx;
        }
        else
        {
            realEndPosx = maxOffset;
        }

        if (realEndPosx == ContentRectrans.anchoredPosition.x)
        {
            if (completeRoll != null)
            {
                completeRoll.Invoke();
            }
            return;
        }

        if (CheckContentOffsetAvailable(direction, realEndPosx) == false)
        {
            return;
        }

        IsScrolling = true;
        if (completeRoll != null)
        {
            MoveTweenner = ContentRectrans.DOAnchorPosX(realEndPosx, tweenTime).OnUpdate(OnUpdateTweenView).OnComplete(() =>
            {
                OnCompleteScrollView();
                completeRoll();
            }).SetEase(mTweenAnimationCurve);
        }
        else
        {
            MoveTweenner = ContentRectrans.DOAnchorPosX(realEndPosx, tweenTime).OnUpdate(OnUpdateTweenView).OnComplete(OnCompleteScrollView).SetEase(mTweenAnimationCurve);
        }
        #endregion
    }