public void StopDragging(ItemSlot _currentSlot) { if (_currentSlot == null && currentSlot == null) { Debug.Log("something went wrong!"); //draggingRect.anchoredPosition = Vector2.zero; //draggingRect = null; //currentDragging = null; currentItem.AddItem(handler.item.item, handler.item.amount); //jump back to original spot return; } currentSlot = _currentSlot; if (currentSlot.Empty) //Current node is empty, just add the item. { currentSlot.AddItem(handler.item.item, handler.item.amount); } else { if (currentSlot.item.item.id == handler.item.item.id) //plus the two together { //check stacking if (currentSlot.item.amount + handler.item.amount > handler.item.item.stack) { int diff = (currentSlot.item.amount + handler.item.amount) - handler.item.item.stack; currentSlot.item.amount = currentSlot.item.item.stack; currentSlot.UpdateUI(); handler.item.amount = diff; handler.UpdateUI(); return; //Return - we dont want to stop dragging yet. } else //else just add the amount { currentSlot.AddItem(handler.item.item, handler.item.amount); } } else { //find out whats currently under InventoryItem under = currentSlot.item; //remove whats currently under, and add the handler item currentSlot.RemoveItem(); currentSlot.AddItem(handler.item.item, handler.item.amount); //add what was under, to holder handler.RemoveItem(); handler.AddItem(under); return; } } handler.RemoveItem(); currentItem = null; }
public void Drop(ItemSlot destination) { Debug.Log("Dropping: " + destination); if (source == null) { return; } if (!IsValid(source.GetItem(), destination)) { return; } // Move or swap items if (destination.IsEmpty()) // Destination is empty, simply move item { if (destination is EquipSlot) { EquipHandler.instance.Add((Equipment)source.GetItem()); } if (source is EquipSlot) { EquipHandler.instance.Remove((Equipment)source.GetItem()); } destination.AddItem(source.GetItem()); source.Clear(); } else { // Check if swap is valid if (!IsValid(destination.GetItem(), source)) { return; } if (destination is EquipSlot) { EquipHandler.instance.Remove((Equipment)destination.GetItem()); EquipHandler.instance.Add((Equipment)source.GetItem()); } Item temp = destination.GetItem(); destination.AddItem(source.GetItem()); source.AddItem(temp); } destination.GetItem().ShowTooltip(); // Show tooltip for moved item }
public void OnSlotSubmitCallback_Function(BaseEventData eventData, InventoryPanel panel, ItemSlot itemSlot, int index) { if (IsEmpty) { if (itemSlot.IsEmpty) { return; } Item itemRemoved = itemSlot.RemoveItem(); if (itemRemoved) { itemSlotSelect.AddItem(itemRemoved); } } else { if (itemSlot.IsEmpty) { Item itemRemoved = itemSlotSelect.RemoveItem(); if (itemRemoved) { itemSlot.AddItem(itemRemoved); } } } }
public static void AddItem(Item item) { int indexOfEmptyItemSlot = -1; for (int i = 0; i < ItemSlots.Count; i++) { ItemSlot itemSlot = ItemSlots[i]; if (itemSlot.Item == null) { indexOfEmptyItemSlot = i; break; } } if (indexOfEmptyItemSlot > -1) { //An empty item slot is found ItemSlot emptyItemSlot = ItemSlots[indexOfEmptyItemSlot]; emptyItemSlot.AddItem(item); } else { //All item slots have items } }
public void AddAmountToItem(InventoryItem item) { Vector2Int index = FindItemSlot(item); ItemSlot slot = itemSlots[index.x, index.y]; slot.AddItem(item.item, item.amount); slot.UpdateUI(); }
private void SetUpCraftingRecipes() { List <Item> craftingRecipes = GameManager.instance.craftingRecipes; foreach (Item recipe in craftingRecipes) { GameObject Go = Instantiate(itemSlotPrefab, craftingItemTranform); ItemSlot slot = Go.GetComponent <ItemSlot>(); slot.AddItem(recipe); } }
private void SetupCraftingRecipes() { List <Item> craftingRecipes = GameManager.instance.craftingRecipes; foreach (Item recipe in craftingRecipes) // Adiciona as receitas na aba Craft { GameObject gameObject = Instantiate(itemSlotPrefab, craftingItemTransform); ItemSlot slot = gameObject.GetComponent <ItemSlot>(); slot.AddItem(recipe); } }
private void addOrRemoveCraftingItem(int childNo, ScriptableBase item) { ItemSlot slot = craftingPanel.GetChild(childNo).GetComponentInChildren <ItemSlot>(); if (item == null) { slot.RemoveItem(); } else { slot.AddItem(item); } }
public void CreateItemSlot(Item item = null) { GameObject slotGO = Instantiate(Resources.Load("ItemSlot"), ItemSlotsParent.transform) as GameObject; ItemSlots.Add(slotGO); ItemSlot slot = slotGO.GetComponent <ItemSlot>(); slot.UI = this; slot.parentToReturn = ItemSlotsParent.transform; slot.parentWhenDrag = GameSettings.instance.CurrentCanvas.transform; if (item != null) { slot.AddItem(item); } //return slot; }
public void LoadInfoInPanel(ScriptableObject info) { Recipe recipe = info as Recipe; for (int i = 0; i < recipesSlots.Length; i++) { if (i < recipesSlots.Length) { recipesSlots[i].AddItem(recipe.materials[i]); resultSlot.AddItem(recipe.resultItem); } else { recipesSlots[i].ClearSlot(); resultSlot.ClearSlot(); } } currentBlacksmith.chosenRecipe = recipe; craftButton.onLeft.AddListener(currentBlacksmith.Craft); }
public void CreateEquipmentWindow(List <Item> items, OnSubmitSlot onPickUpItemCallBack = null, OnSelectSlot onSelectSlotCallBack = null, bool destroyAdictionSlots = true) { if (items.Count == 0) { if (itemtext) { itemtext.text = ""; } if (slots.Count > 0 && destroyAdictionSlots) { for (int i = 0; i < slots.Count; i++) { Destroy(slots[i].gameObject); } slots.Clear(); } return; } bool selecItem = false; onSubmitSlot = onPickUpItemCallBack; onSelectSlot = onSelectSlotCallBack; if (slots == null) { slots = new List <ItemSlot>(); } var count = slots.Count; if (count < items.Count) { for (int i = count; i < items.Count; i++) { var slot = Instantiate(slotPrefab) as ItemSlot; slots.Add(slot); } } else if (count > items.Count) { for (int i = count - 1; i > items.Count - 1; i--) { Destroy(slots[slots.Count - 1].gameObject); slots.RemoveAt(slots.Count - 1); } } count = slots.Count; for (int i = 0; i < items.Count; i++) { ItemSlot slot = null; if (i < items.Count) { slot = slots[i]; slot.AddItem(items[i]); slot.CheckItem(items[i].isInEquipArea); slot.onSubmitSlotCallBack = OnSubmit; slot.onSelectSlotCallBack = OnSelect; var rectTranform = slot.GetComponent <RectTransform>(); rectTranform.SetParent(contentWindow); rectTranform.localPosition = Vector3.zero; rectTranform.localScale = Vector3.one; if (currentItem != null && currentItem == items[i]) { selecItem = true; SetSelectable(slot.gameObject); } } } if (slots.Count > 0 && !selecItem) { StartCoroutine(SetSelectableHandle(slots[0].gameObject)); } if (onCompleteSlotListCallBack != null) { onCompleteSlotListCallBack(slots); } }
private void EquipItem(ItemSlot slot, Item itemToEquip) { slot.AddItem(itemToEquip); }
// Use this for initialization void Awake() { itemSlotCount = 1; equiptableItemSlotCount = 5; itemSlots = new ItemSlot[equiptableItemSlotCount + itemSlotCount]; itemCount = 0; primaryWeaponSlot = new ItemSlot(0); primaryWeaponSlot.slotName = primaryWeaponSlotName; if (primaryWeapon != null) { primaryWeapon = Instantiate(primaryWeapon, transform.position, transform.rotation, transform); primaryWeapon.SetActive(false); primaryWeaponSlot.AddItem(primaryWeapon.name, primaryWeapon); itemCount += 1; } itemSlots[0] = primaryWeaponSlot; secondaryWeaponSlot = new ItemSlot(1); secondaryWeaponSlot.slotName = secondaryWeaponSlotName; if (secondaryWeapon != null) { secondaryWeapon = Instantiate(secondaryWeapon, transform.position, transform.rotation, transform); secondaryWeapon.SetActive(false); secondaryWeaponSlot.AddItem(secondaryWeapon.name, secondaryWeapon); itemCount += 1; } itemSlots[1] = secondaryWeaponSlot; sidearmWeaponSlot = new ItemSlot(2); sidearmWeaponSlot.slotName = sidearmWeaponSlotName; if (sidearmWeapon != null) { sidearmWeapon = Instantiate(sidearmWeapon, transform.position, transform.rotation, transform); sidearmWeapon.SetActive(false); sidearmWeaponSlot.AddItem(sidearmWeapon.name, sidearmWeapon); itemCount += 1; } itemSlots[2] = sidearmWeaponSlot; meleeWeaponSlot = new ItemSlot(3); meleeWeaponSlot.slotName = meleeWeaponSlotName; if (meleeWeapon != null) { meleeWeapon = Instantiate(meleeWeapon, transform.position, transform.rotation, transform); meleeWeapon.SetActive(false); meleeWeaponSlot.AddItem(meleeWeapon.name, meleeWeapon); itemCount += 1; } itemSlots[3] = meleeWeaponSlot; throwableSlot = new ItemSlot(4); throwableSlot.slotName = throwableSlotName; if (throwable != null) { throwable = Instantiate(throwable, transform.position, transform.rotation, transform); throwable.SetActive(false); throwableSlot.AddItem(throwable.name, throwable); itemCount += 1; } itemSlots[4] = throwableSlot; for (int i = equiptableItemSlotCount; i < (equiptableItemSlotCount + itemSlotCount); i++) { ItemSlot newItemSlot = new ItemSlot(i); newItemSlot.slotName = string.Format("Item {0}", i); itemSlots[i] = newItemSlot; } }
public void Tester_AddItem() { Item itemCopy = Instantiate(item); Debug.Log(itemSlot.AddItem(itemCopy)); }
public void Show() { //adds current item to inventory slot inventorySlot.AddItem(ConvertCurrentWeaponToPickup()); }
public void Show() { //adiciona o item atual ao inventario. inventorySlot.AddItem(ConvertCurrentWeaponToPickup()); }