88 lines
1.9 KiB
C#
88 lines
1.9 KiB
C#
using System.Collections;
|
|
using UIWidgets;
|
|
using UnityEngine;
|
|
|
|
namespace UIWidgetsSamples
|
|
{
|
|
[RequireComponent(typeof(ScrollRectEvents))]
|
|
public class TestScrollRectEvents : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
public ListViewIcons ListView;
|
|
|
|
private IObservableList<ListViewIconsItemDescription> data;
|
|
|
|
private bool isStarted;
|
|
|
|
private void Start()
|
|
{
|
|
if (!isStarted)
|
|
{
|
|
isStarted = true;
|
|
ListView.Sort = false;
|
|
data = ListView.DataSource;
|
|
(data as ObservableList<ListViewIconsItemDescription>).Comparison = null;
|
|
ListView.Start();
|
|
ScrollRectEvents component = GetComponent<ScrollRectEvents>();
|
|
if (component != null)
|
|
{
|
|
component.OnPullUp.AddListener(Refresh);
|
|
component.OnPullDown.AddListener(LoadMore);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
Start();
|
|
StartCoroutine(LoadData(0));
|
|
}
|
|
|
|
private IEnumerator LoadData(int start)
|
|
{
|
|
if (start == 0)
|
|
{
|
|
data.Clear();
|
|
}
|
|
WWW www = new WWW("https://ilih.ru/steamspy/?start=" + start);
|
|
yield return www;
|
|
string[] lines = www.text.Split('\n');
|
|
data.BeginUpdate();
|
|
lines.ForEach(ParseLine);
|
|
data.EndUpdate();
|
|
}
|
|
|
|
private void ParseLine(string line)
|
|
{
|
|
if (!(line == string.Empty))
|
|
{
|
|
string[] array = line.Split('\t');
|
|
ListViewIconsItemDescription listViewIconsItemDescription = new ListViewIconsItemDescription();
|
|
listViewIconsItemDescription.Name = string.Format("{0}. {1}", data.Count + 1, array[0]);
|
|
ListViewIconsItemDescription item = listViewIconsItemDescription;
|
|
data.Add(item);
|
|
}
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
StartCoroutine(LoadData(0));
|
|
}
|
|
|
|
public void LoadMore()
|
|
{
|
|
StartCoroutine(LoadData(data.Count));
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
ScrollRectEvents component = GetComponent<ScrollRectEvents>();
|
|
if (component != null)
|
|
{
|
|
component.OnPullUp.RemoveListener(Refresh);
|
|
component.OnPullDown.RemoveListener(LoadMore);
|
|
}
|
|
}
|
|
}
|
|
}
|