拖动物品到快速使用
This commit is contained in:
67
Assets/Scripts/UI/Bag/BagSlotPanel.cs
Normal file
67
Assets/Scripts/UI/Bag/BagSlotPanel.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user