"Infinite Scrolling" for Unity3D Using NGUI's UIScrollView (1st attempt)
Unity3D/NGUI / 2015. 3. 21. 02:12
"Infinite Scrolling" for Unity3D Using NGUI's UIScrollView (1st attempt)
For latest update please check this post instead
I've been using NGUI for UI related work on my Unity project for the past few weeks and it is a breath of fresh air when compared to the stock UnityGUI (OnGUI()).
Part of my project relate to display a relatively large amount of data dynamically (well not very large but in thousands) and instantiating a prefab for each data element didn't seem like a good idea to me :-)
So instead I decided to add some logic to do a scroll view with fixed pool of items that I reuse and position according to the direction of the scroll and get it fed with the correct data.
Although I am sure that there are existing solutions I decided to do my own.
The logic so far is built using UIGrid with fixed cell height for the moment (not well suited for UITable with different cell height) and the panel is using soft clip. the Scroll view is using momentum only (Spring physics breaks my current logic for some reason)
Initialization steps:
I've been using NGUI for UI related work on my Unity project for the past few weeks and it is a breath of fresh air when compared to the stock UnityGUI (OnGUI()).
Part of my project relate to display a relatively large amount of data dynamically (well not very large but in thousands) and instantiating a prefab for each data element didn't seem like a good idea to me :-)
So instead I decided to add some logic to do a scroll view with fixed pool of items that I reuse and position according to the direction of the scroll and get it fed with the correct data.
Although I am sure that there are existing solutions I decided to do my own.
The logic so far is built using UIGrid with fixed cell height for the moment (not well suited for UITable with different cell height) and the panel is using soft clip. the Scroll view is using momentum only (Spring physics breaks my current logic for some reason)
Initialization steps:
- Pool size is calculated using the cell height against the panel height plus some buffer (currently I am using a buffer of 4 list items)
- List items' pool is instantiated with corresponding data from the data list
- A map is maintained to keep track of which data item are used in which list items
- Any item that turns a visible from an invisible state will notify the main controller
- We check the direction of the scroll based on which item is visible (e.g. if the next item is visible means that we are dragging upwards)
- based on the direction we reuse the items at the top or the bottom of the list accordingly (e.g. if direction is up the top item moves to the bottom and get populated with data from the corresponding data element)
This is a first attempt and further posts will follow as the logic evolve.
==UPDATE==
I am in the process of making this component available as open source.
Meanwhile we've launched a free app on Android that uses it called Avatar Messenger
==UPDATE 2==
The component is available as open source
https://github.com/OrangeLabsUK/InfiniteList_NGUI
==UPDATE==
I am in the process of making this component available as open source.
Meanwhile we've launched a free app on Android that uses it called Avatar Messenger
==UPDATE 2==
The component is available as open source
https://github.com/OrangeLabsUK/InfiniteList_NGUI
[파일]
출처 : http://www.geekyhamster.com/2013/12/infinite-scrolling-for-unity3d-using.html
반응형
'Unity3D > NGUI' 카테고리의 다른 글
NGUI UI의 현재 위치 표시하기[수정중] (0) | 2015.05.08 |
---|---|
NGUI 다양한 해상도 대응하기 (2) | 2015.04.21 |
NGUI: Symbols & Emoticons (0) | 2015.02.12 |
NGUI Emoticons (0) | 2015.02.12 |
NGUI UILabel로 Emoticon 넣기.. (0) | 2015.02.12 |