2018-12-31 23:16:28 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace UnityEngine.UI.Extensions.Examples
|
|
|
|
|
{
|
|
|
|
|
public class Example04Scene : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
[SerializeField]
|
2019-03-08 02:11:51 +08:00
|
|
|
|
Example04ScrollView scrollView = null;
|
2018-12-31 23:16:28 +08:00
|
|
|
|
[SerializeField]
|
2019-03-08 02:11:51 +08:00
|
|
|
|
Button prevCellButton = null;
|
2018-12-31 23:16:28 +08:00
|
|
|
|
[SerializeField]
|
2019-03-08 02:11:51 +08:00
|
|
|
|
Button nextCellButton = null;
|
2018-12-31 23:16:28 +08:00
|
|
|
|
[SerializeField]
|
2019-03-08 02:11:51 +08:00
|
|
|
|
Text selectedItemInfo = null;
|
2018-12-31 23:16:28 +08:00
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
prevCellButton.onClick.AddListener(scrollView.SelectPrevCell);
|
|
|
|
|
nextCellButton.onClick.AddListener(scrollView.SelectNextCell);
|
|
|
|
|
scrollView.OnSelectedIndexChanged(HandleSelectedIndexChanged);
|
|
|
|
|
|
|
|
|
|
var cellData = Enumerable.Range(0, 20)
|
|
|
|
|
.Select(i => new Example04CellDto { Message = "Cell " + i })
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
scrollView.UpdateData(cellData);
|
|
|
|
|
scrollView.UpdateSelection(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HandleSelectedIndexChanged(int index)
|
|
|
|
|
{
|
|
|
|
|
selectedItemInfo.text = String.Format("Selected item info: index {0}", index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|