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
|
|
|
|
|
{
|
2018-12-31 23:16:28 +08:00
|
|
|
|
public class Example02ScrollView : FancyScrollView<Example02CellDto, Example02ScrollViewContext>
|
|
|
|
|
{
|
|
|
|
|
[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()
|
|
|
|
|
{
|
|
|
|
|
scrollPositionController.OnUpdatePosition(p => UpdatePosition(p));
|
|
|
|
|
SetContext(new Example02ScrollViewContext { OnPressedCell = OnPressedCell });
|
|
|
|
|
}
|
2017-08-02 17:21:45 +08:00
|
|
|
|
|
2018-12-31 23:16:28 +08:00
|
|
|
|
public void UpdateData(List<Example02CellDto> data)
|
|
|
|
|
{
|
|
|
|
|
cellData = data;
|
|
|
|
|
scrollPositionController.SetDataCount(cellData.Count);
|
|
|
|
|
UpdateContents();
|
|
|
|
|
}
|
2017-08-02 17:21:45 +08:00
|
|
|
|
|
2018-12-31 23:16:28 +08:00
|
|
|
|
void OnPressedCell(Example02ScrollViewCell cell)
|
|
|
|
|
{
|
|
|
|
|
scrollPositionController.ScrollTo(cell.DataIndex, 0.4f);
|
|
|
|
|
Context.SelectedIndex = cell.DataIndex;
|
|
|
|
|
UpdateContents();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-02 17:21:45 +08:00
|
|
|
|
}
|