// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖 using System.Collections.Generic; using FairyGUI; using Fantasy; using UnityEngine; using NBC; using NBF.Fishing2; using UIPanel = NBC.UIPanel; namespace NBF { public partial class BagSlotPanel : UIPanel { private List _items = new List(); protected override void OnInit() { // List.SetVirtual(); } protected override void OnShow() { SetList(); } private void SetList() { var role = App.Main.GetComponent(); var roleBag = role.GetComponent(); _items.Clear(); foreach (var roleBagItem in roleBag.Items) { if (CanShow(roleBagItem)) { _items.Add(roleBagItem); } } List.RemoveChildrenToPool(); List.itemRenderer = OnRenderItem; List.numItems = _items.Count; } void OnRenderItem(int index, GObject obj) { var itemData = _items[index]; if (obj is BagItem bagItem) { bagItem.SetData(itemData); } } private bool CanShow(ItemInfo itemInfo) { if (itemInfo.ItemType == ItemType.Rod) { return true; } return false; } } }