Esempio n. 1
0
 protected override void RollView(LoopViewShowDirection direction)
 {
     if (direction == LoopViewShowDirection.None || (int)direction > (int)LoopViewShowDirection.Left)
     {
         Debug.LogError("RollViewEx  Fail,direction= " + direction);
         return;
     }
     ContentViewShowDirection = Direction = direction;
 }
Esempio n. 2
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);
        }
    }
Esempio n. 3
0
    /// <summary>
    /// 滑动指定固定间隔 指定偏移的距离
    /// </summary>
    /// <param name="direction"></param>
    /// <param name="offsetItem">移动多少个ItemDistance</param>
    /// <param name="tweenTime"></param>
    /// <param name="isAbsDistance"></param>
    public void RollViewEx(LoopViewShowDirection direction, int offsetItem, float tweenTime, bool isAbsDistance, System.Action completeRoll = null)
    {
        if (direction == LoopViewShowDirection.None || (int)direction < (int)LoopViewShowDirection.Left)
        {
            Debug.LogError("RollViewEx  Fail,direction= " + direction);
            return;
        }

        offsetItem = GetContentOffset(direction, offsetItem);
        RollView(direction, offsetItem * ItemDistance, tweenTime, isAbsDistance, completeRoll);
    }
Esempio n. 4
0
    /// <summary>
    /// 检测偏移的参数是否合法 2019/4/24 新增
    /// </summary>
    /// <param name="direction"></param>
    /// <param name="endPos"></param>
    /// <returns></returns>
    protected bool CheckContentOffsetAvailable(LoopViewShowDirection direction, float endPos)
    {
        float offset = 0;

        switch (direction)
        {
        case LoopViewShowDirection.Down:
            offset = endPos - ContentRectrans.anchoredPosition.y;
            if (offset < 0)
            {
                Debug.LogError("显示下面的内容的偏移要大于0");
                return(false);
            }
            break;

        case LoopViewShowDirection.Up:
            offset = endPos - ContentRectrans.anchoredPosition.y;
            if (offset > 0)
            {
                Debug.LogError("显示上面的内容的偏移要小于0");
                return(false);
            }
            break;

        case LoopViewShowDirection.Left:
            offset = endPos - ContentRectrans.anchoredPosition.x;
            if (offset < 0)
            {
                Debug.LogError("显示左边的内容的偏移要大于0");
                return(false);
            }
            break;

        case LoopViewShowDirection.Right:
            offset = endPos - ContentRectrans.anchoredPosition.x;
            if (offset > 0)
            {
                Debug.LogError("显示右边的内容的偏移要小于0");
                return(false);
            }
            break;

        default:
            Debug.LogError("没有定义视图显示方向" + direction);
            return(false);
        }
        return(true);
    }
Esempio n. 5
0
    /// <summary>
    /// 根据视图显示的方向修正数据  (修正数据 2019/4/23 新增 )
    /// </summary>
    /// <param name="direction"></param>
    /// <param name="offsetItem"></param>
    /// <returns></returns>
    protected int GetContentOffset(LoopViewShowDirection direction, int offsetItem)
    {
        int realOffset = offsetItem;

        switch (direction)
        {
        case LoopViewShowDirection.Down:
            if (realOffset < 0)
            {
                Debug.LogError("显示下面的视图 偏移应该为大于0");
                realOffset *= -1;
            }
            break;

        case LoopViewShowDirection.Up:
            if (realOffset > 0)
            {
                Debug.LogError("显示上面的视图 偏移应该为小于0");
                realOffset *= -1;
            }
            break;

        case LoopViewShowDirection.Left:
            if (realOffset < 0)
            {
                Debug.LogError("显示左边的视图 偏移应该为大于0");
                realOffset *= -1;
            }
            break;

        case LoopViewShowDirection.Right:
            if (realOffset > 0)
            {
                Debug.LogError("显示右边的视图 偏移应该为小于0");
                realOffset *= -1;
            }
            break;

        default:
            Debug.LogError("没有定义的类型 " + direction);
            break;
        }

        return(realOffset);
    }
    /// <summary>
    /// 当数据不足 不能无限循环时候的滑动 只能滑动到边界
    /// </summary>
    /// <returns></returns>
    protected float CaculateMaxOffsetDistance(LoopViewShowDirection direction)
    {
        if (DateCount <= 1)
        {
            return(0);
        }

        float absDistance = ItemDistance * (DateCount * 0.5f);

        if (direction == LoopViewShowDirection.Up)
        {
            absDistance = -1 * absDistance;
        }

        if (CheckContentOffsetAvailable(direction, absDistance) == false)
        {
            return(0);
        }
        return(absDistance);
    }
Esempio n. 7
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
    }
Esempio n. 8
0
 /// <summary>
 /// 滑动视图
 /// </summary>
 /// <param name="direction"></param>
 protected abstract void RollView(LoopViewShowDirection direction);