public void updateSlot() { if (!myStack.isEmpty()) { itemIcon.enabled = true; itemIcon.sprite = myStack.getItem().itemIcon; if (myStack.getCount() > 1) { itemAmount.text = myStack.getCount().ToString(); } else { itemAmount.text = string.Empty; } } else { itemIcon.enabled = false; itemAmount.text = string.Empty; } }
private void drawItem() { if (!myStack.isEmpty()) { itemIcon.enabled = true; itemIcon.sprite = myStack.getItem().itemIcon; this.gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(90, 90); if (myStack.getCount() > 1) { //Debug.Log(myStack.getItem().itemIcon); itemAmount.text = myStack.getCount().ToString(); } else { //Debug.Log("draw stack"); itemAmount.text = string.Empty; } } else { disableDragItem(); } }
private void onLeftClick(itemStack currentDraggedItem, itemStack itemCopy) { if (!myStack.isEmpty() && currentDraggedItem.isEmpty()) { inventoryManager.setDragged(itemCopy); this.setSlotContents(itemStack.Empty); } if (myStack.isEmpty() && !currentDraggedItem.isEmpty()) { this.setSlotContents(currentDraggedItem); inventoryManager.setDragged(itemStack.Empty); } if (!myStack.isEmpty() && !currentDraggedItem.isEmpty()) { if (itemStack.areItemsEqual(itemCopy, currentDraggedItem)) { if (itemCopy.canAddTo(currentDraggedItem.getCount())) { itemCopy.increaseAmount(currentDraggedItem.getCount()); this.setSlotContents(itemCopy); inventoryManager.setDragged(itemStack.Empty); } else { int difference = (itemCopy.getCount() + currentDraggedItem.getCount()) - itemCopy.getItem().maxStack; itemCopy.setCount(myStack.getItem().maxStack); itemStack dragCopy = currentDraggedItem.copy(); dragCopy.setCount(difference); this.setSlotContents(itemCopy); inventoryManager.setDragged(dragCopy); } } else { itemStack currentDragCopy = currentDraggedItem.copy(); this.setSlotContents(currentDraggedItem); inventoryManager.setDragged(itemCopy); } } }
// makes a stack public void setStack(itemStack itemIn) { this.item = itemIn.getItem(); this.count = itemIn.getCount(); }
//checks if items can stack or not public bool isItemEqual(itemStack stackIn) { //Debug.Log("Stacking"); return(!stackIn.isEmpty() && this.item == stackIn.getItem()); }