コード例 #1
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();
 }
コード例 #2
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();
         }
     }
 }