private void PopulateItems() { var items = GetVendorItems(); if (items.Count > _vendorGrid.Columns) { _vendorGrid.ResizeGrid(1, items.Count); } foreach (var item in items) { _vendorGrid.AddItem(item); } }
public override void Enter() { CloseShop(); MenuHeader.OnShopButtonClicked += OpenShop; Item[] items = PlayerData.Instance.Items.ToArray(); foreach (Item i in items) { InventoryGrid.AddItem(i, OnSelectItem, false); } }
/// <summary> /// Transfers an amount from one stack to a free space /// </summary> public void OnInventorySplitStackMessage(InventorySplitStackMessage msg) { Item itemFrom = GetItem((uint)msg.FromID); itemFrom.Attributes[GameAttribute.ItemStackQuantityLo] -= (int)msg.Amount; itemFrom.Attributes.SendChangedMessage(_owner.InGameClient); Item item = ItemGenerator.CreateItem(_owner, itemFrom.ItemDefinition); item.Attributes[GameAttribute.ItemStackQuantityLo] = (int)msg.Amount; InventoryGrid targetGrid = (msg.InvLoc.EquipmentSlot == (int)EquipmentSlotId.Stash) ? _stashGrid : _inventoryGrid; targetGrid.AddItem(item, msg.InvLoc.Row, msg.InvLoc.Column); }
//存储物品 void StoreItem(int itemId, int count) { //获取物品数据 Item itemInfo = StaticData.Instance.GetItem(itemId); itemInfo.Count += count; //动态加载物品UI //GameObject itemPrefab = Resources.Load<GameObject>("Prefabs/InventoryItem"); //找到可用格子 InventoryGrid grid = Inventory.Instance.GetAvaliableGrid(itemId); //如果找不到可用的格子 if (grid == null) { Debug.LogWarning("背包已满"); } else { if (grid.ItemCount > 0) { grid.AddItem(count); } else { grid.ItemID = itemId; grid.UpdateGrid(itemId, count); //GameObject itemGo = Instantiate(itemPrefab); ////设置格子的父对象 //itemGo.transform.SetParent(grid.transform); //itemGo.transform.localPosition = Vector3.zero; //itemGo.transform.localScale = Vector3.one; //InventoryItem item = itemGo.GetComponent<InventoryItem>(); //item.Icon = itemInfo.Icon; } } //将添加的物品保存到数据中. //ItemModel.AddItem(itemId); }
public void SpawnItem(Item item) { _inventoryGrid.AddItem(item); }
public void OnClickGetItem() { inventory.AddItem(item); }