/// <summary> /// Event called from inventory UI when unselect an slot /// </summary> /// <param name="slot">target slot</param> public void OnDeselect(vItemSlot slot) { if (equipSlots.Contains(slot as vEquipSlot)) { currentSelectedSlot = null; } }
public void OnSubmitSlot(vItemSlot slot) { if (itemPicker != null) { currentSelectedSlot = slot as vEquipSlot; itemPicker.gameObject.SetActive(true); itemPicker.CreateEquipmentWindow(inventory.items, currentSelectedSlot.itemType, slot.item, OnPickItem); } }
/// <summary> /// Unequip Item of the Slot /// </summary> /// <param name="slot">target slot</param> public void UnequipItem(vEquipSlot slot) { if (slot) { vItem item = slot.item; if (ValidSlots[indexOfEquippedItem].item == item) { lastEquipedItem = item; } slot.RemoveItem(); onUnequipItem.Invoke(this, item); } }
/// <summary> /// Event called to cancel Submit action /// </summary> public void CancelCurrentSlot() { if (currentSelectedSlot == null) { currentSelectedSlot = lastSelectedSlot; } if (currentSelectedSlot != null) { currentSelectedSlot.OnCancel(); } onFinishPickUpItem.Invoke(); }
/// <summary> /// Event called from inventory UI when select an slot /// </summary> /// <param name="slot">target slot</param> public void OnSelectSlot(vItemSlot slot) { if (equipSlots.Contains(slot as vEquipSlot)) { currentSelectedSlot = slot as vEquipSlot; } else { currentSelectedSlot = null; } onSelectEquipArea.Invoke(this); CreateFullItemDescription(slot); }
/// <summary> /// Event called from Inventory slot UI on Submit /// </summary> /// <param name="slot"></param> public void OnSubmitSlot(vItemSlot slot) { lastSelectedSlot = currentSelectedSlot; if (itemPicker != null) { currentSelectedSlot = slot as vEquipSlot; if (setEquipSlotWhenSubmit) { SetEquipSlot(equipSlots.IndexOf(currentSelectedSlot)); } itemPicker.gameObject.SetActive(true); itemPicker.onCancelSlot.RemoveAllListeners(); itemPicker.onCancelSlot.AddListener(CancelCurrentSlot); itemPicker.CreateEquipmentWindow(inventory.items, currentSelectedSlot.itemType, slot.item, OnPickItem); onInitPickUpItem.Invoke(); } }
/// <summary> /// Load inventory items and occupied equipSlots /// </summary> /// <param name="itemManager"></param> public static void LoadInventory(this vItemManager itemManager) { string json = LoadInventoryJasonText(); if (!string.IsNullOrEmpty(json)) { InventoryData data = new InventoryData(); JsonUtility.FromJsonOverwrite(json, data); itemManager.items = data.GetItems(itemManager.itemListData); vEquipArea[] equipAreas = itemManager.inventory.equipAreas; for (int i = 0; i < equipAreas.Length; i++) { if (i < data.equipAreas.Count) { vEquipArea area = equipAreas[i]; EquipAreaData areaData = data.equipAreas[i]; area.indexOfEquippedItem = areaData.indexOfSelectedSlot; for (int e = 0; e < equipAreas[i].equipSlots.Count; e++) { if (e < areaData.slotsData.Count) { SlotData slotData = areaData.slotsData[e]; vEquipSlot slot = equipAreas[i].equipSlots[e]; itemManager.temporarilyIgnoreItemAnimation = true; if (slotData.hasItem) { area.AddItemToEquipSlot(e, itemManager.items[slotData.indexOfItem]); } else { area.RemoveItemOfEquipSlot(e); } } } } } } itemManager.inventory.UpdateInventory(); itemManager.temporarilyIgnoreItemAnimation = false; itemManager.onLoadItems.Invoke(); }
/// <summary> /// Event called from inventory UI to open <see cref="vItemWindow"/> when submit slot /// </summary> /// <param name="slot">target slot</param> public void OnPickItem(vItemSlot slot) { if (!currentSelectedSlot) { currentSelectedSlot = lastSelectedSlot; } if (!currentSelectedSlot) { return; } if (currentSelectedSlot.item != null && slot.item != currentSelectedSlot.item) { currentSelectedSlot.item.isInEquipArea = false; var item = currentSelectedSlot.item; if (item == slot.item) { lastEquipedItem = item; } currentSelectedSlot.RemoveItem(); onUnequipItem.Invoke(this, item); } if (slot.item != currentSelectedSlot.item) { if (onPickUpItemCallBack != null) { onPickUpItemCallBack(this, slot); } currentSelectedSlot.AddItem(slot.item); onEquipItem.Invoke(this, currentSelectedSlot.item); } currentSelectedSlot.OnCancel(); currentSelectedSlot = null; lastSelectedSlot = null; itemPicker.gameObject.SetActive(false); onFinishPickUpItem.Invoke(); }
public void OnSelectSlot(vItemSlot slot) { if (equipSlots.Contains(slot as vEquipSlot)) { currentSelectedSlot = slot as vEquipSlot; } else { currentSelectedSlot = null; } onSelectEquipArea.Invoke(this); if (itemtext != null) { if (slot.item == null) { itemtext.text = ""; } else { text = new StringBuilder(); text.Append(slot.item.name + "\n"); text.AppendLine(slot.item.description); if (slot.item.attributes != null) { for (int i = 0; i < slot.item.attributes.Count; i++) { var _text = InsertSpaceBeforeUpperCase(slot.item.attributes[i].name.ToString()); text.AppendLine(_text + " : " + slot.item.attributes[i].value.ToString()); } } itemtext.text = text.ToString(); } } }