/* * FancyScrollView (https://github.com/setchi/FancyScrollView) * Copyright (c) 2020 setchi * Licensed under MIT (https://github.com/setchi/FancyScrollView/blob/master/LICENSE) */ using System.Collections.Generic; using UnityEngine.UI.Extensions.EasingCore; namespace UnityEngine.UI.Extensions.Examples.FancyScrollViewExample03 { class ScrollView : FancyScrollView { [SerializeField] Scroller scroller = default; [SerializeField] GameObject cellPrefab = default; protected override GameObject CellPrefab => cellPrefab; protected override void Initialize() { base.Initialize(); Context.OnCellClicked = SelectCell; scroller.OnValueChanged(UpdatePosition); scroller.OnSelectionChanged(UpdateSelection); } void UpdateSelection(int index) { if (Context.SelectedIndex == index) { return; } Context.SelectedIndex = index; Refresh(); } public void UpdateData(IList items) { UpdateContents(items); scroller.SetTotalCount(items.Count); } public void SelectCell(int index) { if (index < 0 || index >= ItemsSource.Count || index == Context.SelectedIndex) { return; } UpdateSelection(index); scroller.ScrollTo(index, 0.35f, Ease.OutCubic); } } }