void DropItem(Button slotBtn) { int slotIndex1 = slots.IndexOf(dragItem.transform.GetComponentInParent <Button>().gameObject); int slotIndex2 = slots.IndexOf(slotBtn.gameObject); //CHECK IF I DROP THE SPLIT ITEM if (splitItem == null) { myItems[slotIndex2] = new MyItemValues { itemType = myItems[slotIndex1].itemType, itemValue = myItems[slotIndex1].itemValue }; myItems.Remove(slotIndex1); } else { myItems[slotIndex2] = new MyItemValues { itemType = myItems[slotIndex1].itemType, itemValue = splitValue2 }; splitItem = null; } dragItem.transform.SetParent(slotBtn.transform); SetSlot(); }
void StackItems(Button slotBtn) { GameObject usedItem = dragItem; if (splitItem != null) { usedItem = splitItem; } //REMOVE OLD SLOT FROM DIC AND ADD VALUE TO NEW SLOT int slotIndex1 = slots.IndexOf(usedItem.transform.GetComponentInParent <Button>().gameObject); int slotIndex2 = slots.IndexOf(slotBtn.gameObject); //OLD SLOT int itemValue1 = myItems[slotIndex1].itemValue; //NEW SLOT int itemValue2 = myItems[slotIndex2].itemValue; int changedValue = 0; //OVERWRITE NEW SLOT if (splitItem == null) { if (itemValue1 + itemValue2 > stackValue) { changedValue = (itemValue1 + itemValue2) - stackValue; myItems[slotIndex2].itemValue = stackValue; myItems[slotIndex1].itemValue = changedValue; Destroy(ghostItem); } else { myItems[slotIndex2].itemValue += itemValue1; myItems.Remove(slotIndex1); //DELETE OLD SLOT INFO Destroy(usedItem); Destroy(ghostItem); } } else { print(itemValue1); print(splitValue2); if (itemValue2 + splitValue2 > stackValue) { changedValue = ((itemValue2 + splitValue2) - stackValue) + splitValue1; print(splitValue1); print(splitValue2); //OVERWRITE OLD SLOT myItems[slotIndex1] = new MyItemValues { itemType = myItems[slotIndex2].itemType, itemValue = changedValue }; myItems[slotIndex2].itemValue = stackValue; Destroy(dragItem); Destroy(splitItem); } else { myItems[slotIndex2].itemValue += itemValue1; Destroy(splitItem); } } drag = false; UpdateItems(); }