Files
Fishing2/Assets/Scripts/UI/Bag/BagSlotPanel.cs
2025-11-17 00:06:20 +08:00

67 lines
1.5 KiB
C#

// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
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<ItemInfo> _items = new List<ItemInfo>();
protected override void OnInit()
{
// List.SetVirtual();
}
protected override void OnShow()
{
SetList();
}
private void SetList()
{
var role = App.Main.GetComponent<Role>();
var roleBag = role.GetComponent<RoleBag>();
_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;
}
}
}