Skip to content
 
 

Latest commit

 

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Yao Yifan's unity-scrollview-test

Idea

The basic idea is to have just enough rows to fit the viewport and update each one's data/activeState to 'fake' scrolling. The problem is, how lazy can we be?

My idea has 2 folds:

1. When the scroll is slow enough (specifically, scrolled no more than one row height between updates)

Here I only update anything when

a. any row goes out of sight (I hide it)

b. top row goes fully inside viewport (potentially inserting one row above to be new top row)

c. same as b but for bottom row

At other times the rows will flow with its parent (ScrollView's Content) and the code will do nothing.

2. When the scroll is fast or when it jumped

No other way I could think of except force setting every row

Key Decisions

Not using VerticalLayoutGroup

I guess it had to do with the idea explained above, I am no longer able to use VerticalLayoutGroup in Content. But since I am only updating a row's position when I enable it for the first time, not using VerticalLayoutGroup has turned out to be an optimization

Using LinkedList<T>

Truth be told this is my first time using LinkedList<T> in C#, I was going to write my own Doubly Linked List then I discovered its existence. The idea is I need to access and insert to both top and bottom row (without indexing anything in the middle) inside ScrollView's Content so LinkedList<T> made perfect sense.

Other Optimizations

Removed unused GameObjects in scene and turned off some URP settings

Results Profiled with 20000 rows (a bit extreme, I know)

CPU Load / Draw calls reduction

e1cb1119b4dad8ce59d6ae1bf636113

ab4f91ae2c26f1bdc43fd268402c58e

Worst frame when scrolling

555d78dfe8a45a7c5f190c8014a0416

63815b1f31e20c7e8cfafa74518d255

About

Starter project for how to optimize the default scrollview

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages