public void AddItem(Item _item, int _amount) { //Do we already have this item? then add the amounts foreach (InventoryItem item in items) { if (item.item == _item) { item.amount += _amount; int diff = 0; if (item.amount > item.item.stack) { diff = item.amount - item.item.stack; invUI.AddItem(new InventoryItem(_item, diff), true); } invUI.AddAmountToItem(new InventoryItem(_item, _amount - diff)); return; } } items.Add(new InventoryItem(_item, _amount)); invUI.AddItem(new InventoryItem(_item, _amount)); }
private void _ChangeToGridLayoutDoWrappers() { // Get all items, create new wrappers and fill the new wrappers. int collectionSize = inventoryCollection.items.Length; var items = inventoryCollection.items.Select(o => o.item).Where(o => o != null).ToArray(); // Get rid of old wrappers foreach (var wrapper in inventoryCollection.items) { var c = wrapper as UnityEngine.Component; if (c != null) { Destroy(c.gameObject); } } for (uint i = 0; i < collectionSize; i++) { CreateWapper(gridLayoutElementPrefab, i); } foreach (var item in items) { inventoryCollection.AddItem(item, null, true, false); } LayoutRebuilder.MarkLayoutForRebuild(inventoryCollection.container); }
public void AddItem(Item item) { int itemIndex = -1; if (items.Count > 0) { items.FillAdd(item, ref itemIndex); } else { items.Add(item); itemIndex = 0; } inventoryUI.AddItem(item, itemIndex); }
void returnRemainingBlocks() { foreach (Item item in getItems()) { inventoryUI.AddItem(item); } }
private void InitGrenade() { GameObject grenade = PoolMng.Instance.Pop(PoolType.ItemPool, "Grenade"); Item item = grenade.GetComponent <Item>(); item._itemCount = 3; _inventory.AddItem(item); item._itemCount = 1; PoolMng.Instance.Push(PoolType.ItemPool, grenade, "Grenade"); }
public void AddItem(string name) { if (inventory.ContainsKey(name)) { inventory [name]++; } else { inventory.Add(name, 1); inventoryui.AddItem(name); } inventoryui.UpdateUI(); }
public void AddBlocks(Block origin, int count) { BlockType type = origin.type; if (!inventory.ContainsKey(type)) { inventory [type] = 0; } inventory [type] += count; Item item = createItem(origin, inventory [type]); inventoryUI.AddItem(item); }
public bool AddItem(Item i) { Debug.Log("Adding Item: " + i.GetName() + " to " + this.gameObject.name + "'s Inventory"); bool temp; //invUI.AddItem(i); if (inv.AddItem(i) == true) { temp = true; invUIManager.AddItem(i); } else { temp = false; } return(temp); }
void Update() { if (Input.GetKeyDown(KeyCode.A)) { if (inventory.ContainsKey(word)) { inventory [word] += numb; } else if (itemdatabase.CheckItem(word)) { inventory.Add(word, numb); inventoryui.AddItem(word); } else { return; } inventoryui.UpdateUI(); } if (Input.GetKeyDown(KeyCode.D)) { if (CheckItem()) { Instantiate(itemdatabase.GetItemObject(word), new Vector3(-5, 0, 0), Quaternion.identity); inventory [word]--; if (inventory [word] <= 0) { inventory.Remove(word); inventoryui.RemoveItem(word); } } inventoryui.UpdateUI(); } if (Input.GetKeyDown(KeyCode.S)) { if (!active) { inventoryui.HideInventory(); } else { active = false; inventoryui.UpdateUI(); } } }
//Puts a pocketable item in the player's inventory public void AddItemToInventory(Pocketable item) { //If player currently has an item in their inventory, remove it if (pocketedItem != null) { RemoveItemFromInventory(); } //Set new pocketed item pocketedItem = item; //Handle UI for playable characters if (!(this is Agent)) { inventoryUI.AddItem(item); } item.GetComponent <PhotonView>().RPC("SetItemPocketConditions", RpcTarget.All); }
//Add Item public bool AddItem(Item item) { //Try to find current stack of similar item //int quantityLeft = item.quantity; int availableIndex = -1; for (int i = 0; i < inventory.Length; i++) { if (inventory[i] == null) { if (availableIndex == -1) { Debug.Log("available space found at " + i); availableIndex = i; } } else if (inventory[i].name.Equals(item.name)) { Debug.Log("Would add to stack at index " + i); //Add to stack. //subtract quantity left //if(quantityLeft==0) //return true; } } if (availableIndex == -1) { Debug.Log("Inventory is full or there's no available space for this item"); return(false); } inventory[availableIndex] = item; Debug.Log("Added to " + availableIndex); UI.AddItem(item, availableIndex); return(true); }
/// <summary> /// 添加Item 更新Inventory /// </summary> /// <param name="item"></param> /// <param name="count"></param> public void AddItem(Item item, int count) { if (inventory == null) { inventory = new Dictionary <Item, int>(); } if (count == 0) { Debug.LogError("Item count should > 0."); return; } bool isNewItemForInventory = !inventory.ContainsKey(item); if (isNewItemForInventory) { inventory.Add(item, count); } else { inventory[item] += count; } InventoryUI.AddItem(item, inventory[item]); }
private void LootWindow(int id) { GUI.skin = mySkin; if (GUI.Button(new Rect(_lootWindowRect.width - 20, 0, closeButtonWidth, closeButtonHeight), "x")) { ClearWindow(); } if (chest == null) { return; } if (chest.loot.Count == 0) { ClearWindow(); return; } _lootWindowSlider = GUI.BeginScrollView(new Rect(_offset * 0.5f, 15, _lootWindowRect.width - 10, 70), _lootWindowSlider, new Rect(0, 0, chest.loot.Count * buttonWidth + _offset, buttonHeight + _offset)); for (int cnt = 0; cnt < chest.loot.Count; cnt++) { if (GUI.Button(new Rect(5 + buttonWidth * cnt, _offset, buttonWidth, buttonHeight), new GUIContent(chest.loot[cnt].Icon, chest.loot[cnt].ToolTip()), "Inventory Slot Common")) { Debug.Log(chest.loot[cnt].ToolTip()); //PlayerCharacter.Inventory.Add(chest.loot[cnt]); inv.AddItem(chest.loot[cnt]); chest.loot.RemoveAt(cnt); } } GUI.EndScrollView(); //Debug.Log("Loot: " + GUI.tooltip); //SetToolTip(); }
public void Add(Item _item) { m_items.Add(_item); m_inventoryUI.AddItem(_item); }
/// <summary> /// Add item to inventory when item snapping to bag /// </summary> /// <param name="item">Snapped item</param> private void SnapManagerOnItemAdded(Item.Item item) { _inventoryUI.AddItem(item); Added?.Invoke(item); }