示例#1
0
 /**
  *  When an item is dropped on this slot, swap
  *  it with the one currently in this place
  *
  **/
 public override DraggableItem ItemDropped(DraggableItem item)
 {
     if (item.GetComponent <ActionItem>() != null)
     {
         //	if this is a stackable item, try and stack it
         //	this works but it's _really_ ugly
         //	TODO: maybe there should be a helper that will attempt
         //	this as opposed to implementing it on anything that
         //	requires stackable items.
         StackableInventoryItem stackableSelf = this.item.GetComponent <StackableInventoryItem>();
         StackableInventoryItem stackableItem = item.GetComponent <StackableInventoryItem>();
         if (stackableSelf != null && stackableItem != null)
         {
             //	if we're dragging a single item and dropping it on a max stack
             //	that means we should swap these
             //	TODO: check stack types?
             if (stackableItem.GetCount() == 1 && stackableSelf.GetCount() == stackableSelf.maxCount)
             {
                 items[position] = item.GetComponent <ActionItem>();
                 return(this.item.GetComponent <DraggableItem>());
             }
             else
             {
                 StackableInventoryItem remainder = stackableSelf.AddStackableInventoryItems(stackableItem);
                 if (remainder != null)
                 {
                     return(remainder);
                 }
             }
         }
         else
         {
             items[position] = item.GetComponent <ActionItem>();
             return(this.item.GetComponent <DraggableItem>());
         }
     }
     return(null);
 }
示例#2
0
        /**
         *  An item was dropped on this slot. Swap it with the
         *  item currently in that position and return it or
         *  stack it if it's a stackable item
         *
         **/
        public override DraggableItem ItemDropped(DraggableItem item)
        {
            if (item.GetComponent <InventoryItem>() != null)
            {
                StackableInventoryItem stackableItem = item.GetComponent <StackableInventoryItem>();
                StackableInventoryItem stackableSelf = this.item.GetComponent <StackableInventoryItem>();

                //	if this is a stackable item, stack it
                if (stackableItem != null && stackableSelf != null)
                {
                    if (!stackableSelf.IsMaxed())
                    {
                        return(stackableSelf.AddStackableInventoryItems(stackableItem));
                    }
                }

                //	otherwise, swap it
                GameObject tmpInventoryItem = inventory[inventoryPosition.x, inventoryPosition.y];
                inventory[inventoryPosition.x, inventoryPosition.y] = item.gameObject;
                return(tmpInventoryItem.GetComponent <InventoryItem>());
            }
            return(null);
        }