Skip to content

Auto Scroll

Luke Mirman edited this page Sep 7, 2022 · 2 revisions

Auto Scroll Component

By default the canvas Scrollbar does not move its position when a Selectable is selected.

The purpose of this script then is to to update a Scrollbar's value to include the rect of a child selectable inside the viewport when selected.

Usage

  1. In the canvas hierarchy add the Autoscroll to the game object with the ScrollRect component.
  2. Enter playmode and verify the ScrollRect component updates when a child Selectable is selected.
  3. If you are dynamically adding or removing selectables into the scroll rect make sure to use either the SetDirty(int) method or RefreshList() to update the candidates for the Autoscroll list. This method is somewhat expensive so only invoke it when necessary.

Limitations

  • Currently only vertical position is supported, however a future update will add support for horizontal position updating.
Clone this wiki locally