Files
Fishing2/Assets/Scripts/UI/Shops/FishingShopPanel.cs
2025-05-23 00:26:58 +08:00

106 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
using System.Collections.Generic;
using FairyGUI;
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()
{
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)
// {
// Hide();
// }
}
protected override void OnHide()
{
base.OnHide();
}
protected override void OnDestroy()
{
base.OnDestroy();
}
}
}