// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖 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 _data = new List(); 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(); } } }