Super ScrollView
for UGUI 2.2 Overview LoopListView2 is a component attaching to the same gameobject of UGUI ScrollRect. It helps the UGUI ScrollRect to support any count items with high performance and memory-saving. For a ScrollRect with 10,000 items, LoopListView2 does not really create 10,000 items, but create a few items based on the size of the viewport. When the ScrollRect moving up, for example, the LoopListView2 component would check the topmost item’s position, and once the topmost item is out of the viewport, then the LoopListView2 component would recycle the topmost item, and at the same time check the downmost item’s position, and once the downmost item is near the bottom of the viewport , the LoopListView2 component would call the onGetItemByIndex handler to create a new item and then positon the new created item under the downmost item, so the new created item becomes the new downmost item. Every item can use a different prefab and can have different height/width. There are several examples to help you learn the LoopListView2 component, in the folder with path : Assets -> SuperScrollView -> Demo -> Scenes. And Menu scene is the entry.
Inspector Settings
In the Inspector, to make sure the LoopListView2 component works well, there are several parameters need to set: ItemPrefabList: this is the existing items to clone. Every item can use a different prefab and every prefab can have different default padding( the amount of spacing between each item in the scrollrect). And also, every prefab can have different default x local pos(for Vertical scrollrect) or default y local pos(for Horizontal scrollrect), and here, is called (X/Y)PosOffset. Every prefab has a pool for getting and recycling action, and the InitCreateCount is the count created in pool at start. In fact, in runtime, every item can have different padding and (X/Y)PosOffset, you can change an item’s padding and (X/Y)PosOffset in your onGetItemByIndex callback. You can get/set them by LoopListViewItem2. Padding and LoopListViewItem2. StartPosOffset. Important note: All the itemPrefab’s localScale need to be (1,1,1). SupportScrollbar: if checked, the LoopListView2 component would support scrollbar.
upper right corner. ViewPortSnapPivot is the location of the snap pivot point of the ScrollRect ViewPort, defined as a fraction of the size of the rectangle itself. 0,0 corresponds to the lower left corner while 1,1 corresponds to the upper right corner. ArrangeType: the scroll direction, there are four types: (1) TopToBottom: this type is used for a vertical scrollrect, and the item0,item1,…itemN are positioned one by one from top to bottom in the scrollrect viewport, just like the following:
Important Public Method
InitListView method is to initiate the LoopListView2 component. There are 3 parameters: itemTotalCount: the total item count in the scrollview. If this parameter is set -1, then means there are infinite items, and scrollbar would not be supported, and the ItemIndex can be from –MaxInt to +MaxInt. If this parameter is set sssa value >=0 , then the ItemIndex can only be from 0 to itemTotalCount -1. onGetItemByIndex: 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. LoopListViewItem2 is the return value of onGetItemByIndex Every created item has a LoopListViewItem2 component auto attached:
The mItemIndex property indicates the item’s index in the list, as mentioned above, if itemTotalCount is set -1, then the mItemIndex can be from –MaxInt to +MaxInt. If itemTotalCount is set a value >=0 , then the mItemIndex can only be from 0 to itemTotalCount -1.
The mItemId property indicates the item’s id. This property is set when the item is created or
fetched from pool, and will no longer change until the item is recycled back to pool.
The following codes is an example of onGetItemByIndex:
LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index)
{
if (index < 0 || index >= DataSourceMgr.Get.TotalItemCount)
{
return null;
}
//get the data to showing
ItemData itemData = DataSourceMgr.Get.GetItemDataByIndex(index);
if(itemData == null)
{
return null;
}
/*get a new item. Every item can use a different prefab, the parameter of the
NewListViewItem is
the prefab’name.
And all the prefabs should be listed in ItemPrefabList in LoopListView2 Inspector
Setting */
LoopListViewItem2 item = listView.NewListViewItem("ItemPrefab1");
ListItem2 itemScript = item.GetComponent
'프로그래밍 > Unity' 카테고리의 다른 글
FPS (Frame Per Sec) Display 표시, 출력하기 (0) | 2018.09.10 |
---|---|
Snapshot / Screenshot 생성 (0) | 2018.07.27 |
[Unity3D] Singleton (0) | 2018.01.03 |
[Unity3D] Enable 과 Awake (0) | 2018.01.03 |
public 변수를 컴포넌트에서 읽기 전용으로 하기 (0) | 2017.11.16 |
댓글