// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖 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(); private RoleBag _roleBag; protected override void OnInit() { } protected override void OnShow() { var role = App.Main.GetComponent(); _roleBag = role.GetComponent(); SetList(); SetSlotList(); } #region 物品列表 private void SetList() { _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); bagItem.draggable = true; } } #endregion #region 快速选择列表 private void SetSlotList() { SlotList.RemoveChildrenToPool(); for (int index = 0; index < 7; index++) { if (SlotList.AddItemFromPool() is BagSlotItem slotItem) { slotItem.SetData(index, _roleBag.GetSlotItem(index)); slotItem.OnChangeSlot = OnChangeSlotItem; } } } private void OnChangeSlotItem(int index, long id) { _roleBag.SetSlot(index, id).OnCompleted(OnChangeSlotItemDone); } private void OnChangeSlotItemDone() { SetSlotList(); // SlotList.RefreshVirtualList(); } #endregion private bool CanShow(ItemInfo itemInfo) { if (itemInfo.ItemType == ItemType.Rod) { return true; } return false; } } }