Click or drag to resize

MultiplePrefabsExample Class

Example implementation demonstrating the use of 2 different views holders, representing 2 different models into their own prefab, with a common Title property, displayed in a Text found on both prefabs.

The only constrain is for the models to have a common ancestor class and for the views holders to also have a common ancestor class

Also, the BidirectionalModel is used to demonstrate how the data can flow from the model to the views, but also from the views to the model (i.e. this model updates when the user changes the value of its corresponding slider)

At the core, everything's the same as in other example implementations, so if something's not clear, check them (SimpleTutorial is a good start)

Inheritance Hierarchy
SystemObject
  Object
    Component
      Behaviour
        MonoBehaviour
          frame8.Logic.Misc.Visual.UI.ScrollRectItemsAdapterSRIAMyParams, BaseVH
            frame8.ScrollRectItemsAdapter.MultiplePrefabsExampleMultiplePrefabsExample

Namespace:  frame8.ScrollRectItemsAdapter.MultiplePrefabsExample
Assembly:  Assembly-CSharp (in Assembly-CSharp.dll) Version: 0.0.0.0
Syntax
C#
public class MultiplePrefabsExample : SRIA<MyParams, BaseVH>, 
	ExpandCollapseOnClickISizeChangesHandler

The MultiplePrefabsExample type exposes the following members.

Constructors
  NameDescription
Public methodMultiplePrefabsExample
Top
Methods
  NameDescription
Public methodChangeItemsCount

Self-explanatory. See ItemCountChangeMode in order to understand how change modes differ from each other.

If you display each item's index, you can override this method to update the views, in case an Insert/Remove operation will occur, which may naturally change the indices of some items

(Overrides SRIATParams, TItemViewsHolderChangeItemsCount(ItemCountChangeMode, Int32, Int32, Boolean, Boolean).)
Protected methodCreateViewsHolder
Creates either a BidirectionalVH or a ExpandableVH, depending on the type of the model at index itemIndex. Calls Init(RectTransform, Int32, Boolean, Boolean) on it, which instantiates the prefab etc.
(Overrides SRIATParams, TItemViewsHolderCreateViewsHolder(Int32).)
Protected methodIsRecyclable
Overriding the base implementation, which always returns true. In this case, a views holder is recyclable only if its CanPresentModelType(Type) returns true for the model at index indexOfItemThatWillBecomeVisible
(Overrides SRIATParams, TItemViewsHolderIsRecyclable(TItemViewsHolder, Int32, Double).)
Public methodOnExpandedStateChanged
Protected methodStart (Overrides SRIATParams, TItemViewsHolderStart.)
Protected methodUpdate (Overrides SRIATParams, TItemViewsHolderUpdate.)
Protected methodUpdateViewsHolder

Here the data in your model should be bound to the views. Use newOrRecycled.ItemIndex (ItemIndex) to retrieve its associated model

Note that views holders are re-used (this is the main purpose of this adapter), so a views holder's views will contain data from its previously associated model and if,

for example, you're downloading an image to be set as an icon, it makes sense to first clear the previous one (and probably temporarily replace it with a generic "Loading" image)

Note that this is not called for items that will remain visible after an Insert or Remove operation is done

(Overrides SRIATParams, TItemViewsHolderUpdateViewsHolder(TItemViewsHolder).)
Top
Fields
  NameDescription
Public fieldaverageValuesInModelsText
Shows the average of all values in all models of type BidirectionalModel
Top
Version Information

Optimized ScrollView Adapter

Supported in: 4.0, 3.0
See Also