// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖 using System; using System.Collections.Generic; using FairyGUI; using Fantasy; using UnityEngine; using NBC; using NBF.Fishing2; using UIPanel = NBC.UIPanel; namespace NBF { public partial class BagSelectPanel : UIPanel { //context.data private static Action _selectCallBack; // private static ItemType _itemType; private static readonly List _itemTypes = new List(); private long _selectedId; // private List _items; // public static void Show(ItemType itemType, Action callBack) // { // Show(new[] { itemType }, callBack); // } public static void Show(Action callBack, params ItemType[] itemTypes) { _itemTypes.Clear(); _itemTypes.AddRange(itemTypes); _selectCallBack = callBack; // List Show(); } protected override void OnInit() { IsModal = true; this.AutoAddClick(OnClick); List.OnDoubleClickItem += OnDoubleClickItem; List.OnClickItem += OnClickItem; } protected override void OnShow() { _selectedId = 0; SetList(); } protected override void OnDestroy() { List.OnClickItem -= OnClickItem; List.OnDoubleClickItem -= OnDoubleClickItem; } private void OnClick(GComponent btn) { if (btn == BtnCancel) { Hide(); } else if (btn == BtnConfirm) { if (_selectedId > 0) { _selectCallBack?.Invoke(_selectedId); } Hide(); } } private void OnClickItem(object item) { if (item is BagItem bagItem) { _selectedId = bagItem.ItemInfo.Id; } } private void OnDoubleClickItem(object item) { if (item is BagItem bagItem) { _selectedId = bagItem.ItemInfo.Id; _selectCallBack?.Invoke(bagItem.ItemInfo.Id); Hide(); } } private void SetList() { // var role = Game.Main.GetComponent(); // var roleBag = role.GetComponent(); List items = RoleModel.Instance.GetItemListData(_itemTypes.ToArray()); List.SetListData(items); } } }