Click or drag to resize

Com.ForbiddenByte.OSA.Core Namespace

 
Classes
  ClassDescription
Public classAbstractViewsHolder
Class representing the concept of a Views Holder, i.e. a class that references some views and the id of the data displayed by those views. Usually, the root and its child views, once created, don't change, but ItemIndex does, after which the views will change their data.
Public classBaseItemViewsHolder
Public classBaseParams

Input params to be passed to Init

This can be used Monobehaviour's field and exposed via inspector (most common case)

Or can be manually constructed, depending on what's easier in your context

Public classBaseParamsEffects
Public classBaseParamsOptimization
Public classItemsDescriptor
Public classOSATParams, TItemViewsHolder

Old name: ScrollRectItemsAdapter (renamed in 3.0 to SRIA, and in v4.1 to OSA as a final name - short for Optimized ScrollView Adapter)

Base abstract component that you need to extend in order to provide an implementation for CreateViewsHolder(Int32) and UpdateViewsHolder(TItemViewsHolder). Should be attached instead of the Unity's ScrollRect component. Any views holder should extend BaseItemViewsHolder, so you can provide it as the generic parameter TItemViewsHolder when implementing OSA. Extending BaseParams is optional. Based on your needs. Provide it as generic parameter TParams when implementing OSA

How it works, in a nutshell (it's recommended to manually go through the example code in order to fully understand the mechanism):

1. create your own implementation of BaseItemViewsHolder, let's name it MyItemViewsHolder

2. create your own implementation of BaseParams (if needed), let's name it MyParams

3. create your own implementation of OSA<MyParams, MyItemViewsHolder>, let's name it MyScrollViewAdapter

4. instantiate MyScrollViewAdapter

5. call MyScrollViewAdapter.ResetItems(int) once (and any time your dataset is changed) and the following things will happen:

5.1. CollectItemsSizes(ItemCountChangeMode, Int32, Int32, ItemsDescriptor) will be called (which you can optionally implement to provide your own sizes, if known beforehand)

5.2. CreateViewsHolder(Int32) will be called for enough items to fill the viewport. Once a ViewsHolder is created, it'll be re-used when it goes off-viewport

- newOrRecycledViewsHolder.root will be null, so you need to instantiate your prefab, assign it and call newOrRecycledViewsHolder.CollectViews(). Alternatively, you can call its Init(GameObject, Int32, Boolean, Boolean) method, which can do a lot of things for you, mainly instantiate the prefab and (if you want) call CollectViews() for you

- after creation, only UpdateViewsHolder(TItemViewsHolder) will be called for it when its represented item changes and becomes visible

5.3. UpdateViewsHolder(TItemViewsHolder) will be called when an item is to be displayed or simply needs updating:

- use ItemIndex to get the item index, so you can retrieve its associated model from your data set (most common practice is to store the data list in your Params implementation)

- root is not null here (given the views holder was properly created in CreateViewsHolder(..)). It's assigned a valid object whose UI elements only need their values changed (common practice is to implement helper methods in the views holder that take the model and update the views themselves)

ResetItems(Int32, Boolean, Boolean) is also called when the viewport's size changes (like for orientation changes on mobile or window resizing on sandalone platforms)

*NOTE: No LayoutGroup (vertical/horizontal/grid) on content panel are allowed, since all the layouting is delegated to this adapter

Protected classOSATParams, TItemViewsHolderNestingManager
Public classOSAConst
Public classOSADebugger
Public classSnapper8
Public classSRIATParams, TItemViewsHolder Obsolete.
Interfaces
  InterfaceDescription
Public interfaceIOSA
Contains commonly used members so that an OSATParams, TItemViewsHolder instance can be referenced abstractly (since instances of derived generic classes cannot be referenced by a variable of base type).
Public interfaceISRIA Obsolete.
Enumerations
  EnumerationDescription
Public enumerationBaseParamsContentGravity
Represents how often or when the optimizer does his core loop: checking for any items that need to be created, destroyed, disabled, displayed, recycled
Public enumerationBaseParamsOrientationEnum
Public enumerationItemCountChangeMode