public void MoveItem(Slot newSlot, int transferCount = -1, bool oppisiteStack = false) { // Remember: Clicking an inventory button moves the buttons slot into the hand, ergo it calls this function with the hand slot as newSlot. Item otherItem = newSlot.item; int otherCount = newSlot.count; if (transferCount == -1) transferCount = count; if (Item.Equals (item, otherItem)) { // Both sides have items, are the same item and metadata. int total = otherCount + transferCount; int max = item.prefab.maxStack; if (total <= max) { newSlot.ChangeCount (transferCount); ChangeCount (-transferCount); } else { // Other slot does not have enough room for this slots item, // so it adds what it can and subtracts those from this slot. int remaining = max - otherCount; newSlot.ChangeCount (remaining); ChangeCount (-remaining); } if (oppisiteStack) { newSlot.MoveItem (this); } // Other slot has enough room for this slots items, so it adds // this slots item and removes item from this slot. } else { // Both sides are not the same item, or any side doesn't have an item. Simply swap spaces. // If recieving side is empty, only the transferCount should be moved, if not, and transferCount // isn't the entire stack, do nothing. if (newSlot.item == null) { newSlot.count = transferCount; newSlot.item = item; ChangeCount (-transferCount); }else if (transferCount == count) { newSlot.count = count; newSlot.item = item; item = otherItem; count = otherCount; } } newSlot.ForceButtonUpdate (); ForceButtonUpdate (); }