This commit is contained in:
2025-05-23 00:26:58 +08:00
parent 2ca8eac832
commit 4b7a6b1dc8
22 changed files with 194 additions and 22 deletions

View File

@@ -1,21 +1,51 @@
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
using System.Collections.Generic;
using FairyGUI;
using UnityEngine;
using NBC;
using UIPanel = NBC.UIPanel;
namespace NBF
{
public class ListDataBase
{
public string title;
}
public class ShopGearData : ListDataBase
{
}
public partial class FishingShopPanel : UIPanel
{
public override string UIPackName => "Shop";
public override string UIResName => "FishingShopPanel";
private List<ListDataBase> _data = new List<ListDataBase>();
protected override void OnInit()
{
base.OnInit();
this.AutoAddClick(OnClick);
Menu.OnClose += Hide;
for (int i = 0; i < 10; i++)
{
var data = new ListDataBase();
data.title = "Title" + i;
_data.Add(data);
for (int j = 0; j < 30; j++)
{
var item = new ShopGearData();
item.title = $"Item {i}-" + j;
_data.Add(item);
}
}
// List.SetVirtual();
List.itemProvider = GetListItemResource;
List.itemRenderer = OnRenderItem;
List.numItems = _data.Count;
}
protected override void OnShow()
@@ -23,6 +53,38 @@ namespace NBF
base.OnShow();
}
void OnRenderItem(int index, GObject obj)
{
if (obj is ListTitleItem titleItem)
{
titleItem.width = List.width - 60;
titleItem.height = 47;
}
// else
// {
// obj.width = 224;
// obj.height = 320;
// }
}
//根据索引的不同返回不同的资源URL
string GetListItemResource(int index)
{
var itemData = _data[index];
if (itemData is ShopGearData shopItem)
{
return ShopGearItem.URL;
}
if (itemData is ListDataBase item)
{
return ListTitleItem.URL;
}
return List.defaultItem;
}
private void OnClick(GComponent btn)
{
// if (btn == BtnClose)