### Populate Scroll View with Data (C#) Source: https://github.com/setchi/fancyscrollview/blob/master/README.md Example script to initialize and populate the custom scroll view with a list of data items. It creates sample data and passes it to the scroll view's update method. ```csharp using UnityEngine; using System.Linq; class EntryPoint : MonoBehaviour { [SerializeField] MyScrollView myScrollView = default; void Start() { var items = Enumerable.Range(0, 20) .Select(i => new ItemData($"Cell {i}")) .ToArray(); myScrollView.UpdateData(items); } } ``` -------------------------------- ### FancyScrollView API Reference Source: https://github.com/setchi/fancyscrollview/blob/master/README.md Provides an overview of the FancyScrollView API, detailing core classes and their methods for implementing scrollable lists and grids in Unity. ```apidoc FancyScrollView __init__(GameObject cellPrefab, GameObject container, Action onValueChanged) cellPrefab: The prefab for the scrollable cells. container: The parent transform for the cells. onValueChanged: Callback for scroll position changes. UpdateContents(IList items) Updates the scroll view with a new list of data items. Parameters: items: A list of data items to display. UpdatePosition(float position) Updates the visual position of cells based on the scroll position. Parameters: position: The current scroll position (0.0 to 1.0). CellPrefab Property to get or set the cell prefab. FancyCell UpdateContent(TItemData itemData) Called when the cell's content needs to be updated with new data. Parameters: itemData: The data item for this cell. UpdatePosition(float position) Called to update the cell's visual state based on its scroll position. Parameters: position: The scroll position relative to the cell's visibility. Scroller OnValueChanged(Action callback) Registers a callback to be invoked when the scroll value changes. Parameters: callback: The action to execute on value change. SetTotalCount(int count) Sets the total number of items in the scrollable list. Parameters: count: The total item count. ``` -------------------------------- ### Implement Custom Scroll View (C#) Source: https://github.com/setchi/fancyscrollview/blob/master/README.md Custom scroll view implementation inheriting from FancyScrollView. It manages the cell prefab, updates scroll positions, and handles the data binding process. ```csharp using UnityEngine; using System.Linq; using FancyScrollView; class MyScrollView : FancyScrollView { [SerializeField] Scroller scroller = default; [SerializeField] GameObject cellPrefab = default; protected override GameObject CellPrefab => cellPrefab; void Start() { scroller.OnValueChanged(base.UpdatePosition); } public void UpdateData(IList items) { base.UpdateContents(items); scroller.SetTotalCount(items.Count); } } ``` -------------------------------- ### Implement Custom Cell (C#) Source: https://github.com/setchi/fancyscrollview/blob/master/README.md Custom cell implementation inheriting from FancyCell. It defines how data is displayed within a single UI cell and how the cell's appearance updates based on its scroll position. ```csharp using UnityEngine; using UnityEngine.UI; using FancyScrollView; class MyCell : FancyCell { [SerializeField] Text message = default; public override void UpdateContent(ItemData itemData) { message.text = itemData.Message; } public override void UpdatePosition(float position) { // position is a value from 0.0 to 1.0 // You can freely control the scroll appearance based on position } } ``` -------------------------------- ### Define Item Data Model (C#) Source: https://github.com/setchi/fancyscrollview/blob/master/README.md Defines a simple data structure to hold information for each item displayed in the scroll view. This class serves as the data payload passed to custom cells. ```csharp class ItemData { public string Message { get; } public ItemData(string message) { Message = message; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.