/// <summary>
    /// 根据已经存在的项创建其他的项 如果项太多会删除数据
    /// </summary>
    /// <param name="dex"></param>
    /// <returns></returns>
    protected virtual RectTransform CrateGameObject(int dex)
    {
        RectTransform target       = null;
        bool          isCreateItem = false; //标示是否是创建的项or 复用的项

        if (dex < ContentRectrans.childCount)
        {
            target = ContentRectrans.GetChildEX(dex);
        }
        else
        {
            target       = GameObject.Instantiate(mItemPrefab, ContentRectrans).transform as RectTransform;
            isCreateItem = true;
        }
        LoopCircleItem circleItem = target.GetAddComponent <LoopCircleItem>();

        circleItem.InitialedView(dex);
        AllLoopCircleItems[target] = circleItem;

        if (isCreateItem && OnItemCreateAct != null)
        {
            OnItemCreateAct(target, circleItem);
        }
        return(target);
    }
Example #2
0
    /// <summary>
    /// 将最后不可见的项移动到第一个
    /// </summary>
    /// <param name="firstItem"></param>
    protected virtual void ScrollUpDirection(RectTransform lastItem, RectTransform firstItem)
    {
        lastItem.SetAsFirstSibling();
        lastItem.anchoredPosition = new Vector2(firstItem.anchoredPosition.x, firstItem.anchoredPosition.y + ItemDistance);

        LoopCircleItem lastloopCircle  = AllLoopCircleItems[lastItem];
        LoopCircleItem firstloopCircle = AllLoopCircleItems[firstItem];

        lastloopCircle.InitialedView(firstloopCircle.DataIndex - 1);

        if (OnItemShowAct != null)
        {
            OnItemShowAct.Invoke(lastItem, lastloopCircle);
        }
    }
    /// <summary>
    /// 将第一个不可见的项移动到末尾
    /// </summary>
    /// <param name="firstItem"></param>
    protected virtual void ScrollRightDirection(RectTransform firstItem, RectTransform lastItem)
    {
        //if (firstItem == null)
        //    firstItem = ContentRectrans.GetChildEX(0);

        firstItem.SetAsLastSibling();
        firstItem.anchoredPosition = new Vector2(lastItem.anchoredPosition.x + ItemDistance, lastItem.anchoredPosition.y);
        LoopCircleItem firstloopCircle = AllLoopCircleItems[firstItem];
        LoopCircleItem lastloopCircle  = AllLoopCircleItems[lastItem];

        firstloopCircle.InitialedView(lastloopCircle.DataIndex + 1);
        if (OnItemShowAct != null)
        {
            OnItemShowAct.Invoke(firstItem, firstloopCircle);
        }
    }
    /// <summary>
    ///将最后一个不可见得项移动到开头
    /// </summary>
    /// <param name="operateItem"></param>
    protected virtual void ScrollLeftDirection(RectTransform lastItem, RectTransform firstItem)
    {
        //if (lastItem == null)
        //    lastItem = ContentRectrans.GetChildEX(ContentRectrans.childCount - 1);
        lastItem.SetAsFirstSibling();
        lastItem.anchoredPosition = new Vector2(firstItem.anchoredPosition.x - ItemDistance, firstItem.anchoredPosition.y);

        LoopCircleItem lastloopCircle  = AllLoopCircleItems[lastItem];
        LoopCircleItem firstloopCircle = AllLoopCircleItems[firstItem];

        lastloopCircle.InitialedView(firstloopCircle.DataIndex - 1);
        if (OnItemShowAct != null)
        {
            OnItemShowAct.Invoke(lastItem, lastloopCircle);
        }
    }