# Loop Scroll Rect
## v1.06
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)
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.
## Example
Please refer to `InitOnStart.cs` for quick example implmentation. It's high recommended for implmentating your own cache pool.
### 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.
没有合适的资源?快使用搜索试试~ 我知道了~
LoopScrollRect-master.zip
共68个文件
meta:21个
asset:20个
cs:12个
需积分: 5 1 下载量 180 浏览量
2021-11-26
09:21:55
上传
评论
收藏 1.22MB ZIP 举报
温馨提示
unity实现scrollview无限滑动
资源详情
资源评论
资源推荐
收起资源包目录
LoopScrollRect-master.zip (68个子文件)
LoopScrollRect-master
ProjectSettings
ProjectVersion.txt 85B
InputManager.asset 6KB
PackageManagerSettings.asset 1003B
TagManager.asset 421B
EditorSettings.asset 399B
GraphicsSettings.asset 2KB
VersionControlSettings.asset 188B
PresetManager.asset 146B
VFXManager.asset 353B
DynamicsManager.asset 642B
ClusterInputManager.asset 114B
ProjectSettings.asset 18KB
NavMeshAreas.asset 955B
UnityConnectSettings.asset 742B
Physics2DSettings.asset 953B
NetworkManager.asset 159B
AudioManager.asset 293B
TimeManager.asset 183B
QualitySettings.asset 4KB
EditorBuildSettings.asset 145B
UserSettings
EditorUserSettings.asset 597B
Images
demo2.gif 263KB
ScrollCell.png 43KB
demo3.gif 221KB
ScrollToIndex.gif 236KB
LoopVerticalScrollRect.png 28KB
demo1.gif 379KB
Content.png 48KB
LICENSE 1KB
Assets
Scripts.meta 201B
Demo
Scripts.meta 201B
DemoScene.unity 71KB
DemoScene.unity.meta 183B
Prefabs.meta 192B
Scripts
ScrollIndexCallback2.cs.meta 275B
InitOnStart.cs 1KB
ScrollIndexCallback3.cs 333B
ScrollIndexCallback1.cs 2KB
ScrollIndexCallback3.cs.meta 275B
ScrollIndexCallback1.cs.meta 275B
InitOnStart.cs.meta 263B
ScrollIndexCallback2.cs 544B
Prefabs
ScrollCell3.prefab 6KB
ScrollCell1.prefab 6KB
ScrollCell1.prefab.meta 180B
ScrollCell2.prefab 6KB
ScrollCell2.prefab.meta 180B
ScrollCell3.prefab.meta 180B
Scripts
Editor
SGMenuOptions.cs 8KB
SGMenuOptions.cs.meta 263B
SGDefaultControls.cs 7KB
SGDefaultControls.cs.meta 263B
LoopScrollRectInspector.cs.meta 263B
LoopScrollRectInspector.cs 1KB
LoopScrollDataSource.cs 187B
LoopScrollPrefabSource.cs 211B
LoopHorizontalScrollRect.cs.meta 275B
LoopScrollPrefabSource.cs.meta 262B
LoopScrollRect.cs 58KB
LoopVerticalScrollRect.cs 7KB
LoopScrollDataSource.cs.meta 262B
LoopHorizontalScrollRect.cs 7KB
LoopScrollRect.cs.meta 275B
LoopVerticalScrollRect.cs.meta 275B
Editor.meta 192B
Demo.meta 201B
.gitignore 391B
README.md 4KB
共 68 条
- 1
记住拥抱
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0