本文整理汇总了C#中Slot.MoveItem方法的典型用法代码示例。如果您正苦于以下问题:C# Slot.MoveItem方法的具体用法?C# Slot.MoveItem怎么用?C# Slot.MoveItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slot
的用法示例。
在下文中一共展示了Slot.MoveItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MoveItem
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 ();
}