59 lines
928 B
C#
59 lines
928 B
C#
using UIWidgets;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UIWidgetsSamples
|
|
{
|
|
[RequireComponent(typeof(Button))]
|
|
public class TestListView : MonoBehaviour
|
|
{
|
|
public ListView listView;
|
|
|
|
private Button button;
|
|
|
|
private ObservableList<string> items;
|
|
|
|
private int click;
|
|
|
|
private void Start()
|
|
{
|
|
button = GetComponent<Button>();
|
|
if (button != null)
|
|
{
|
|
button.onClick.AddListener(Click);
|
|
}
|
|
}
|
|
|
|
private void Click()
|
|
{
|
|
if (click == 0)
|
|
{
|
|
items = listView.DataSource;
|
|
items.Add("Added from script 0");
|
|
items.Add("Added from script 1");
|
|
items.Add("Added from script 2");
|
|
items.Remove("Caster");
|
|
click++;
|
|
}
|
|
else if (click == 1)
|
|
{
|
|
items.Clear();
|
|
click++;
|
|
}
|
|
else if (click == 2)
|
|
{
|
|
items.Add("test");
|
|
click++;
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (button != null)
|
|
{
|
|
button.onClick.RemoveListener(Click);
|
|
}
|
|
}
|
|
}
|
|
}
|