# Loop Scroll Rect
## v1.04
__This project works for Unity 5.2 or newer.__ I havn't tested older versions and any Pull Requests are welcomed.
These scripts help make your ScrollRect `Reusable`, because it will only build cells when needed. If you have a large number of cells in a scroll rect, you absolutely need it! It will save a lot of time loading and draw call, along with memory in use, while still working smoothly.
中文说明请看[这里](http://qiankanglai.me/2015/08/15/LoopScrollRect/)。
## Demo
Demo for Loop Scroll Rect. Each cell knows its own index, and it is able to modify its content/size/color easily.
Also ScrollBar is supported now! It supports both vertical & horizontal directions, back and forth.
![Demo1](Images/demo1.gif)
![Demo2](Images/demo2.gif)
Demo without mask. As you can see, the cells are only instantiated when needed and recycled.
![Demo3](Images/demo3.gif)
**New**: Scroll to Index
![ScrollToIndex](Images/ScrollToIndex.gif)
## Introduction
The original idea comes from @ivomarel's [InfinityScroll](https://github.com/ivomarel/InfinityScroll). After serveral refactorisations, I almost rewrite all the codes:
- Avoid using `sizeDelta` directly since it doesn't always mean size
- Support GridLayout
- Avoid blocking when dragging back
- Take advantage of pool rather than instantiate/destroy every time
- Improve some other details for performance
- Supports reverse direction
- **Supports ScrollBar** (this doesn't work in Infinite mode, and may behavior strange for cells with different size)
Also, I modified [Easy Object Pool](https://www.assetstore.unity3d.com/cn/#!/content/31928) for recycling the cells.
My scripts copies `ScrollRect` from [UGUI](https://bitbucket.org/Unity-Technologies/ui) rather than inherit `ScrollRect` like InfinityScroll. I need to modify some private variants to make dragging smooth. All my codes is wrapped with comments like `==========LoopScrollRect==========`, making maintaining a little easier.
### Infinite Version
If you need scroll infinitely, you can simply set `totalCount` to a negative number.
### Quick Jump
I've implemented a simple version with `Coroutine`. You can use the following API:
public void SrollToCell(int index, float speed)
Here is a corner case unsolved yet: You can't jump to the last cells which cannot be pulled to the start.
## Example: Loop Vertical Scroll Rect
These steps may be confusing, so you can just open the demo scene and copy & paste :D
You can also remove EasyObjPool and use your pool instead.
- Prepare cell prefabs
- The cell needs `Layout Element` attached and preferred width/height
- You should add a script receiving message `void ScrollCellIndex (int idx) `
![ScrollCell](Images/ScrollCell.png)
- Right click in Hierarchy and click **UI/Loop Horizontal Scroll Rect** or **UI/Loop Vertical Scroll Rect**. It is the same for these two in the Component Menu.
- Init in Start: call Refill cells automatically when Start
- Prefab Pool: the EasyObjPool gameObject
- Prefab Pool Name: the corresponding pool in step 1
- Total Count: How many cells are available (index: 0 ~ TotalCount-1)
- Threshold: How many additional pixels of content should be prepared before start or after end?
- ReverseDirection: If you want scroll from bottom or right, you should toggle this
- Clear Cells: remove existing cells and keep uninitialized
- Refill Cells: initialize and fill up cells
![LoopVerticalScrollRect](Images/LoopVerticalScrollRect.png)
If you need scroll from top or left, setting content's pivot to 1 and disable ReverseDirection. Otherwise, you should set 0 to pivot and enable ReverseDirection (I have made `VerticalScroll_Reverse` in the demo scene as reference).
I highly suggests you trying these parameters by hand. More details can be found in the demo scene.
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
UGUI ScrollRect滚动优化:无限循环利用Item.zip (68个子文件)
LoopScrollRect-master
Assets
Demo
Resources
ScrollCell2.prefab.meta 188B
ScrollCell3.prefab 6KB
ScrollCell2.prefab 6KB
ScrollCell1.prefab 6KB
ScrollCell3.prefab.meta 188B
ScrollCell1.prefab.meta 188B
Resources.meta 201B
DemoScene.unity.meta 183B
Scripts
ScrollIndexCallback1.cs.meta 275B
ScrollIndexCallback2.cs.meta 275B
ScrollIndexCallback3.cs 333B
ScrollIndexCallback2.cs 544B
ScrollIndexCallback1.cs 2KB
ScrollIndexCallback3.cs.meta 275B
Scripts.meta 201B
DemoScene.unity 64KB
Scripts
EasyObjectPool
EasyObjectPool.cs.meta 275B
ResourceManager.cs 4KB
EasyObjectPool.cs 5KB
ResourceManager.cs.meta 263B
LoopHorizontalScrollRect.cs 3KB
Editor.meta 192B
LoopHorizontalScrollRect.cs.meta 275B
LoopVerticalScrollRect.cs.meta 275B
EasyObjectPool.meta 201B
InitOnStart.cs 337B
LoopScrollPrefabSource.cs 804B
LoopScrollRect.cs.meta 275B
LoopScrollPrefabSource.cs.meta 262B
Editor
SGDefaultControls.cs 7KB
LoopScrollRectInspector.cs.meta 263B
SGMenuOptions.cs.meta 263B
SGDefaultControls.cs.meta 263B
LoopScrollRectInspector.cs 1KB
SGMenuOptions.cs 8KB
LoopScrollDataSource.cs.meta 262B
LoopScrollDataSource.cs 952B
LoopVerticalScrollRect.cs 3KB
LoopScrollRect.cs 50KB
InitOnStart.cs.meta 263B
Demo.meta 201B
Scripts.meta 201B
ProjectSettings
Physics2DSettings.asset 953B
ProjectVersion.txt 25B
GraphicsSettings.asset 2KB
TimeManager.asset 183B
AudioManager.asset 293B
EditorBuildSettings.asset 145B
UnityConnectSettings.asset 742B
QualitySettings.asset 4KB
ClusterInputManager.asset 114B
DynamicsManager.asset 642B
TagManager.asset 421B
InputManager.asset 6KB
NavMeshAreas.asset 955B
NetworkManager.asset 159B
EditorSettings.asset 399B
ProjectSettings.asset 18KB
Images
LoopVerticalScrollRect.png 28KB
demo2.gif 263KB
Content.png 48KB
ScrollToIndex.gif 236KB
demo3.gif 221KB
demo1.gif 379KB
ScrollCell.png 43KB
LICENSE 1KB
README.md 4KB
.gitignore 399B
共 68 条
- 1
资源评论
- 长春之之2018-04-18unity3d版本问题没能成功运行,不过也谢谢分享
- DvLee10242019-12-03测试下。。。
- 大超z2019-01-31代码自己写的吗,功能好齐全,代码比较多
Master-Xue
- 粉丝: 147
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功