Beispiel #1
0
 //reset the layout param, such as column count, item width/height,padding size
 public void ResetGridViewLayoutParam(int itemTotalCount, GridViewLayoutParam layoutParam)
 {
     if (mListViewInited == false)
     {
         Debug.LogError("ResetLayoutParam can not use before LoopStaggeredGridView.InitListView are called!");
         return;
     }
     mScrollRect.StopMovement();
     SetListItemCount(0, true);
     RecycleAllItem();
     ClearAllTmpRecycledItem();
     mLayoutParam = layoutParam;
     if (mLayoutParam == null)
     {
         Debug.LogError("layoutParam can not be null!");
         return;
     }
     if (mLayoutParam.CheckParam() == false)
     {
         return;
     }
     mGroupCount = mLayoutParam.mColumnOrRowCount;
     mViewPortRectTransform.GetLocalCorners(mViewPortRectLocalCorners);
     mContainerTrans.anchoredPosition3D = Vector3.zero;
     mItemTotalCount = itemTotalCount;
     UpdateLayoutParamAutoValue();
     mItemGroupList.Clear();
     for (int i = 0; i < mGroupCount; ++i)
     {
         StaggeredGridItemGroup group = new StaggeredGridItemGroup();
         group.Init(this, mItemTotalCount, i, GetNewItemByGroupAndIndex);
         mItemGroupList.Add(group);
     }
     UpdateContentSize();
 }
Beispiel #2
0
        /*
         * To update a item by itemIndex.if the itemIndex-th item is not visible, then this method will do nothing.
         * Otherwise this method will first call onGetItemByIndex(itemIndex) to get a updated item and then reposition all visible items'position.
         */
        public void RefreshItemByItemIndex(int itemIndex)
        {
            ItemIndexData indexData = GetItemIndexData(itemIndex);

            if (indexData == null)
            {
                return;
            }
            StaggeredGridItemGroup group = GetItemGroupByIndex(indexData.mGroupIndex);

            group.RefreshItemByIndexInGroup(indexData.mIndexInGroup);
        }
Beispiel #3
0
        /*
         * For a vertical scrollrect, when a visible item’s height changed at runtime,
         * then this method should be called to let the LoopStaggeredGridView component reposition all visible items’ position of the same group (that is the same column / row).
         * For a horizontal scrollrect, when a visible item’s width changed at runtime,
         * then this method should be called to let the LoopStaggeredGridView component reposition all visible items’ position of the same group (that is the same column / row).
         */
        public void OnItemSizeChanged(int itemIndex)
        {
            ItemIndexData indexData = GetItemIndexData(itemIndex);

            if (indexData == null)
            {
                return;
            }
            StaggeredGridItemGroup group = GetItemGroupByIndex(indexData.mGroupIndex);

            group.OnItemSizeChanged(indexData.mIndexInGroup);
        }
Beispiel #4
0
        //To get the visible item by itemIndex. If the item is not visible, then this method return null.
        public LoopStaggeredGridViewItem GetShownItemByItemIndex(int itemIndex)
        {
            ItemIndexData indexData = GetItemIndexData(itemIndex);

            if (indexData == null)
            {
                return(null);
            }
            StaggeredGridItemGroup group = GetItemGroupByIndex(indexData.mGroupIndex);

            return(group.GetShownItemByIndexInGroup(indexData.mIndexInGroup));
        }
Beispiel #5
0
 public void ResetGridViewLayoutParam(int itemTotalCount, GridViewLayoutParam layoutParam)
 {
     if (!this.mListViewInited)
     {
         Debug.LogError((object)"ResetLayoutParam can not use before LoopStaggeredGridView.InitListView are called!");
     }
     else
     {
         this.mScrollRect.StopMovement();
         this.SetListItemCount(0, true);
         this.RecycleAllItem();
         this.ClearAllTmpRecycledItem();
         this.mLayoutParam = layoutParam;
         if (this.mLayoutParam == null)
         {
             Debug.LogError((object)"layoutParam can not be null!");
         }
         else
         {
             if (!this.mLayoutParam.CheckParam())
             {
                 return;
             }
             this.mGroupCount = this.mLayoutParam.mColumnOrRowCount;
             this.mViewPortRectTransform.GetLocalCorners(this.mViewPortRectLocalCorners);
             this.mContainerTrans.set_anchoredPosition3D(Vector3.get_zero());
             this.mItemTotalCount = itemTotalCount;
             this.UpdateLayoutParamAutoValue();
             this.mItemGroupList.Clear();
             for (int groupIndex = 0; groupIndex < this.mGroupCount; ++groupIndex)
             {
                 StaggeredGridItemGroup staggeredGridItemGroup = new StaggeredGridItemGroup();
                 staggeredGridItemGroup.Init(this, this.mItemTotalCount, groupIndex, new Func <int, int, LoopStaggeredGridViewItem>(this.GetNewItemByGroupAndIndex));
                 this.mItemGroupList.Add(staggeredGridItemGroup);
             }
             this.UpdateContentSize();
         }
     }
 }
Beispiel #6
0
 /*
  * InitListView method is to initiate the LoopStaggeredGridView component. There are 4 parameters:
  * itemTotalCount: the total item count in the scrollview, this parameter should be >=0.
  * layoutParam: this class is very sample, and you need new a GridViewLayoutParam instance and set the values you want.
  * onGetItemByItemIndex: when an item is getting in the scrollrect viewport, this Action will be called with the item’ index as a parameter, to let you create the item and update its content.
  * LoopStaggeredGridViewItem is the return value of onGetItemByItemIndex
  * Every created item has a LoopStaggeredGridViewItem component auto attached
  */
 public void InitListView(int itemTotalCount, GridViewLayoutParam layoutParam,
                          System.Func <LoopStaggeredGridView, int, LoopStaggeredGridViewItem> onGetItemByItemIndex,
                          StaggeredGridViewInitParam initParam = null)
 {
     mLayoutParam = layoutParam;
     if (mLayoutParam == null)
     {
         Debug.LogError("layoutParam can not be null!");
         return;
     }
     if (mLayoutParam.CheckParam() == false)
     {
         return;
     }
     if (initParam != null)
     {
         mDistanceForRecycle0        = initParam.mDistanceForRecycle0;
         mDistanceForNew0            = initParam.mDistanceForNew0;
         mDistanceForRecycle1        = initParam.mDistanceForRecycle1;
         mDistanceForNew1            = initParam.mDistanceForNew1;
         mItemDefaultWithPaddingSize = initParam.mItemDefaultWithPaddingSize;
     }
     mScrollRect = gameObject.GetComponent <ScrollRect>();
     if (mScrollRect == null)
     {
         Debug.LogError("LoopStaggeredGridView Init Failed! ScrollRect component not found!");
         return;
     }
     if (mDistanceForRecycle0 <= mDistanceForNew0)
     {
         Debug.LogError("mDistanceForRecycle0 should be bigger than mDistanceForNew0");
     }
     if (mDistanceForRecycle1 <= mDistanceForNew1)
     {
         Debug.LogError("mDistanceForRecycle1 should be bigger than mDistanceForNew1");
     }
     mScrollRectTransform   = mScrollRect.GetComponent <RectTransform>();
     mContainerTrans        = mScrollRect.content;
     mViewPortRectTransform = mScrollRect.viewport;
     mGroupCount            = mLayoutParam.mColumnOrRowCount;
     if (mViewPortRectTransform == null)
     {
         mViewPortRectTransform = mScrollRectTransform;
     }
     if (mScrollRect.horizontalScrollbarVisibility == ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport && mScrollRect.horizontalScrollbar != null)
     {
         Debug.LogError("ScrollRect.horizontalScrollbarVisibility cannot be set to AutoHideAndExpandViewport");
     }
     if (mScrollRect.verticalScrollbarVisibility == ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport && mScrollRect.verticalScrollbar != null)
     {
         Debug.LogError("ScrollRect.verticalScrollbarVisibility cannot be set to AutoHideAndExpandViewport");
     }
     mIsVertList            = (mArrangeType == ListItemArrangeType.TopToBottom || mArrangeType == ListItemArrangeType.BottomToTop);
     mScrollRect.horizontal = !mIsVertList;
     mScrollRect.vertical   = mIsVertList;
     AdjustPivot(mViewPortRectTransform);
     AdjustAnchor(mContainerTrans);
     AdjustContainerPivot(mContainerTrans);
     InitItemPool();
     mOnGetItemByItemIndex = onGetItemByItemIndex;
     if (mListViewInited == true)
     {
         Debug.LogError("LoopStaggeredGridView.InitListView method can be called only once.");
     }
     mListViewInited = true;
     mViewPortRectTransform.GetLocalCorners(mViewPortRectLocalCorners);
     mContainerTrans.anchoredPosition3D = Vector3.zero;
     mItemTotalCount = itemTotalCount;
     UpdateLayoutParamAutoValue();
     mItemGroupList.Clear();
     for (int i = 0; i < mGroupCount; ++i)
     {
         StaggeredGridItemGroup group = new StaggeredGridItemGroup();
         group.Init(this, mItemTotalCount, i, GetNewItemByGroupAndIndex);
         mItemGroupList.Add(group);
     }
     UpdateContentSize();
 }
Beispiel #7
0
 public void InitListView(
     int itemTotalCount,
     GridViewLayoutParam layoutParam,
     Func <LoopStaggeredGridView, int, LoopStaggeredGridViewItem> onGetItemByItemIndex,
     StaggeredGridViewInitParam initParam = null)
 {
     this.mLayoutParam = layoutParam;
     if (this.mLayoutParam == null)
     {
         Debug.LogError((object)"layoutParam can not be null!");
     }
     else
     {
         if (!this.mLayoutParam.CheckParam())
         {
             return;
         }
         if (initParam != null)
         {
             this.mDistanceForRecycle0        = initParam.mDistanceForRecycle0;
             this.mDistanceForNew0            = initParam.mDistanceForNew0;
             this.mDistanceForRecycle1        = initParam.mDistanceForRecycle1;
             this.mDistanceForNew1            = initParam.mDistanceForNew1;
             this.mItemDefaultWithPaddingSize = initParam.mItemDefaultWithPaddingSize;
         }
         this.mScrollRect = (ScrollRect)((Component)this).get_gameObject().GetComponent <ScrollRect>();
         if (Object.op_Equality((Object)this.mScrollRect, (Object)null))
         {
             Debug.LogError((object)"LoopStaggeredGridView Init Failed! ScrollRect component not found!");
         }
         else
         {
             if ((double)this.mDistanceForRecycle0 <= (double)this.mDistanceForNew0)
             {
                 Debug.LogError((object)"mDistanceForRecycle0 should be bigger than mDistanceForNew0");
             }
             if ((double)this.mDistanceForRecycle1 <= (double)this.mDistanceForNew1)
             {
                 Debug.LogError((object)"mDistanceForRecycle1 should be bigger than mDistanceForNew1");
             }
             this.mScrollRectTransform   = (RectTransform)((Component)this.mScrollRect).GetComponent <RectTransform>();
             this.mContainerTrans        = this.mScrollRect.get_content();
             this.mViewPortRectTransform = this.mScrollRect.get_viewport();
             this.mGroupCount            = this.mLayoutParam.mColumnOrRowCount;
             if (Object.op_Equality((Object)this.mViewPortRectTransform, (Object)null))
             {
                 this.mViewPortRectTransform = this.mScrollRectTransform;
             }
             if (this.mScrollRect.get_horizontalScrollbarVisibility() == 2 && Object.op_Inequality((Object)this.mScrollRect.get_horizontalScrollbar(), (Object)null))
             {
                 Debug.LogError((object)"ScrollRect.horizontalScrollbarVisibility cannot be set to AutoHideAndExpandViewport");
             }
             if (this.mScrollRect.get_verticalScrollbarVisibility() == 2 && Object.op_Inequality((Object)this.mScrollRect.get_verticalScrollbar(), (Object)null))
             {
                 Debug.LogError((object)"ScrollRect.verticalScrollbarVisibility cannot be set to AutoHideAndExpandViewport");
             }
             this.mIsVertList = this.mArrangeType == ListItemArrangeType.TopToBottom || this.mArrangeType == ListItemArrangeType.BottomToTop;
             this.mScrollRect.set_horizontal(!this.mIsVertList);
             this.mScrollRect.set_vertical(this.mIsVertList);
             this.AdjustPivot(this.mViewPortRectTransform);
             this.AdjustAnchor(this.mContainerTrans);
             this.AdjustContainerPivot(this.mContainerTrans);
             this.InitItemPool();
             this.mOnGetItemByItemIndex = onGetItemByItemIndex;
             if (this.mListViewInited)
             {
                 Debug.LogError((object)"LoopStaggeredGridView.InitListView method can be called only once.");
             }
             this.mListViewInited = true;
             this.mViewPortRectTransform.GetLocalCorners(this.mViewPortRectLocalCorners);
             this.mContainerTrans.set_anchoredPosition3D(Vector3.get_zero());
             this.mItemTotalCount = itemTotalCount;
             this.UpdateLayoutParamAutoValue();
             this.mItemGroupList.Clear();
             for (int groupIndex = 0; groupIndex < this.mGroupCount; ++groupIndex)
             {
                 StaggeredGridItemGroup staggeredGridItemGroup = new StaggeredGridItemGroup();
                 staggeredGridItemGroup.Init(this, this.mItemTotalCount, groupIndex, new Func <int, int, LoopStaggeredGridViewItem>(this.GetNewItemByGroupAndIndex));
                 this.mItemGroupList.Add(staggeredGridItemGroup);
             }
             this.UpdateContentSize();
         }
     }
 }