当前位置: 首页>>代码示例>>C#>>正文


C# Slot.MoveItem方法代码示例

本文整理汇总了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 ();
        }
开发者ID:Lomztein,项目名称:Microsquad,代码行数:55,代码来源:Inventory.cs


注:本文中的Slot.MoveItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。