2017-08-02 17:21:45 +08:00
|
|
|
|
using System.Collections.Generic;
|
2018-12-31 23:16:28 +08:00
|
|
|
|
using UnityEngine;
|
2017-08-02 17:21:45 +08:00
|
|
|
|
|
|
|
|
|
namespace UnityEngine.UI.Extensions.Examples
|
|
|
|
|
{
|
|
|
|
|
public class Example03ScrollView : FancyScrollView<Example03CellDto, Example03ScrollViewContext>
|
|
|
|
|
{
|
|
|
|
|
[SerializeField]
|
2019-03-08 02:11:51 +08:00
|
|
|
|
ScrollPositionController scrollPositionController = null;
|
2017-08-02 17:21:45 +08:00
|
|
|
|
|
2018-12-31 23:16:28 +08:00
|
|
|
|
void Awake()
|
2017-08-02 17:21:45 +08:00
|
|
|
|
{
|
2018-12-31 23:16:28 +08:00
|
|
|
|
scrollPositionController.OnUpdatePosition(p => UpdatePosition(p));
|
2017-08-02 17:21:45 +08:00
|
|
|
|
SetContext(new Example03ScrollViewContext { OnPressedCell = OnPressedCell });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateData(List<Example03CellDto> data)
|
|
|
|
|
{
|
|
|
|
|
cellData = data;
|
|
|
|
|
scrollPositionController.SetDataCount(cellData.Count);
|
|
|
|
|
UpdateContents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnPressedCell(Example03ScrollViewCell cell)
|
|
|
|
|
{
|
|
|
|
|
scrollPositionController.ScrollTo(cell.DataIndex, 0.4f);
|
2018-12-31 23:16:28 +08:00
|
|
|
|
Context.SelectedIndex = cell.DataIndex;
|
2017-08-08 02:33:53 +08:00
|
|
|
|
UpdateContents();
|
|
|
|
|
}
|
2017-08-02 17:21:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|