AlicizaX/Client/Assets/Scripts/Hotfix/GameLogic/UI/TestRecyclerView.cs

44 lines
956 B
C#
Raw Normal View History

2025-12-26 14:23:01 +08:00
using System.Collections;
using System.Collections.Generic;
using AlicizaX.UI;
using UnityEngine;
public class TestData : ISimpleViewData
{
public string Name;
}
public class TestRecyclerView : MonoBehaviour
{
public RecyclerView itemListView;
2025-12-26 15:39:41 +08:00
public UGLoopList<TestData> list;
public int scrollIndex = 0;
public ScrollAlignment scrollAlignment;
public float scrollOffset;
public float scrollDuration;
2025-12-26 14:23:01 +08:00
void Start()
{
2025-12-26 15:39:41 +08:00
list = UGListCreateHelper.CreateLoop<TestData>(itemListView, OnBtnItemClick);
2025-12-26 14:23:01 +08:00
List<TestData> datas = new();
for (int i = 0; i < 150; i++)
{
datas.Add(new TestData { Name = $"Item {i}" });
}
list.Data = datas;
2025-12-26 15:39:41 +08:00
2025-12-26 14:23:01 +08:00
}
private void OnBtnItemClick(TestData obj)
{
Debug.Log(obj.Name);
}
2025-12-26 15:39:41 +08:00
public void Scroll()
{
list.ScrollTo(scrollIndex,scrollAlignment,scrollOffset,true,duration:scrollDuration);
}
2025-12-26 14:23:01 +08:00
}