protected override ItemUI SpawnItemUI(Item item, int slotIndex) { ItemUI itemUI = null; switch (item) { case WeaponItem _: itemUI = Instantiate(weaponItemUI.gameObject).GetComponent <ItemUI>(); break; case ActiveItem _: itemUI = Instantiate(activeItemUI.gameObject).GetComponent <ItemUI>(); break; case ConsumableItem _: itemUI = Instantiate(consumableItemUI.gameObject).GetComponent <ItemUI>(); break; case ResourceItem _: itemUI = Instantiate(resourceItemUI.gameObject).GetComponent <ItemUI>(); break; } if (itemUI != null) { itemUI.Init(item.Info.ItemName, slotUIs[slotIndex].transform, rightClickAction); } return(itemUI); }
/// <summary> /// Show item in inventory UI /// </summary> /// <param name="item"></param> private void AddInventory(ItemData data) { // instantiate gameobject ItemUI ui = GameObject.Instantiate(itemUiPrefab.gameObject, itemsParent).GetComponent <ItemUI>(); ui.Init(data, () => ExamineItem(data)); // add to dictionary itemsUI.Add(data.item, ui); }
protected override ItemUI SpawnItemUI(Item item, int slotIndex) { ItemUI itemUI = Instantiate(consumableItemUI.gameObject).GetComponent <ItemUI>(); if (itemUI != null) { itemUI.Init(item.Info.ItemName, slotUIs[slotIndex].transform, rightClickAction); } return(itemUI); }
public void UpdateItemsPanel(Level level) { foreach (Item item in level.FindObjects) { if (!panelPool.ContainsKey(item.ObjectName)) { ItemUI panelElement = Instantiate(itemUI, itemsPanel); panelElement.Init(level.TryGetItemsNumber(item), item.Sprite, item); panelPool.Add(item.ObjectName, panelElement); } } }
public void AddItemInPanel(Item item) { if (item.MyLevel == GameManager.Instance.CurrentLevel) { if (panelPool.ContainsKey(item.ObjectName)) { panelPool[item.ObjectName].ItemsNumber += 1; } else { ItemUI panelElement = Instantiate(itemUI, itemsPanel); panelElement.Init(1, item.Sprite, item); panelPool.Add(item.ObjectName, panelElement); } } }
public void SetInventory(Inventory inventory) { //first clean up previous objects from our view for (var i = 0; i < itemsUI.Count; ++i) { itemsUI[i].SetInactive(); itemsUI[i].ResetItem(); } //now fill in the new inventory for (var i = 0; i < inventory.items.Count; ++i) { Item itemInventory = inventory.items[i]; //do not exceed our pool range.. if (i >= itemsUI.Count) { break; } ItemUI item = itemsUI[i]; var quality = itemInventory.quality == GameEnums.Quality.NORMAL ? "" : "[" + itemInventory.quality + "]"; var title = "[" + NGUIText.EncodeColor(_itemsCreator.GetColor(itemInventory.quality)) + "]" + quality + "[-]" + " Item " + i; var description = itemInventory.GetType().Name; item.Init( itemInventory.objectId, title, description, itemInventory.price.ToString() + "$", itemInventory.data.amount.ToString(), "NGUI"); item.SetActive(); } Invoke("RepositionGrid", 0.1f); }