com.unity.uiextensions.nosa.../Examples/FancyScrollView/02_CellEventHandling/Example02ScrollView.cs

32 lines
957 B
C#
Raw Normal View History

using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.UI.Extensions.Examples
{
public class Example02ScrollView : FancyScrollView<Example02CellDto, Example02ScrollViewContext>
{
[SerializeField]
ScrollPositionController scrollPositionController = null;
void Awake()
{
scrollPositionController.OnUpdatePosition(p => UpdatePosition(p));
SetContext(new Example02ScrollViewContext { OnPressedCell = OnPressedCell });
}
public void UpdateData(List<Example02CellDto> data)
{
cellData = data;
scrollPositionController.SetDataCount(cellData.Count);
UpdateContents();
}
void OnPressedCell(Example02ScrollViewCell cell)
{
scrollPositionController.ScrollTo(cell.DataIndex, 0.4f);
Context.SelectedIndex = cell.DataIndex;
UpdateContents();
}
}
}