예제 #1
0
    public void OnPointerClick(PointerEventData data)
    {
        GUI.ExitTooltip();
        Item item = GUI.Items[(int)Slot];

        //Pick up item (only works for ingredient slots)
        if (data.pointerId == -1 && Slot != UpgradeGUI.Slot.Result && item != null && !Inventory.isBeingDragged)
        {
            int emptySlot = Inventory.inventory.GetInventoryIndex(item.ID);
            Inventory.ShowDraggedItem(item, emptySlot);
            GUI.UpdateSlot(Slot, null);
        }
        //Place dragged item in empty slot
        else if (data.pointerId == -1 && Slot != UpgradeGUI.Slot.Result && item == null && Inventory.isBeingDragged)
        {
            GUI.UpdateSlot(Slot, Inventory.DraggedItem);
            //Update slot number server side
            Network.RemoveInventoryItem(Inventory.DraggedItem.Slot, Inventory.DraggedItem.Count);
            Inventory.DraggedItem.Slot = GetSlotIndex();
            Network.AddInventoryItem(Inventory.DraggedItem);
            //Clear dragged item
            Inventory.DeleteDraggedItem();
        }
        //Swap dragged item with full slot
        else if (data.pointerId == -1 && Slot != UpgradeGUI.Slot.Result && item != null && Inventory.isBeingDragged)
        {
            Item itemBeingDragged = Inventory.DraggedItem;
            Inventory.inventory.inventory[Inventory.DraggedSlotNumber] = item;      //.inventory.inventory.inventory.Inventory
            GUI.Items[(int)Slot] = itemBeingDragged;
            //Update server
            //Remove items
            Network.RemoveInventoryItem(itemBeingDragged.Slot, itemBeingDragged.Count);
            Network.RemoveInventoryItem(item.Slot, item.Count);
            //Swap slot numbers
            itemBeingDragged.Slot = GetSlotIndex();
            item.Slot             = Inventory.DraggedSlotNumber;
            //Add items
            Network.AddInventoryItem(itemBeingDragged);
            Network.AddInventoryItem(item);
            //Clear dragged item
            Inventory.DeleteDraggedItem();
        }
        //Right click on non-empty slot
        if (data.pointerId == -2 && item != null)
        {
            GUI.ShowContextMenu(GetComponent <RectTransform>(), Slot);
        }
    }
예제 #2
0
 public void OnPointerClick(PointerEventData data)
 {
     _gui.ExitToolTip();
     //Pick up item
     if (data.pointerId == -1 && _inventory.inventory[SlotNumber] != null && !_gui.isBeingDragged)
     {
         _gui.ShowDraggedItem(_inventory.inventory[SlotNumber], SlotNumber);
         _inventory.inventory[SlotNumber] = null;
     }
     //Place dragged item in empty slot
     else if (data.pointerId == -1 && _inventory.inventory[SlotNumber] == null && _gui.isBeingDragged)
     {
         _inventory.inventory[SlotNumber] = _gui.DraggedItem;
         //Update server
         _network.RemoveInventoryItem(_gui.DraggedItem.Slot, _gui.DraggedItem.Count);
         _gui.DraggedItem.Slot = SlotNumber;
         _network.AddInventoryItem(_gui.DraggedItem);
         //Clear dragged item
         _gui.DeleteDraggedItem();
     }
     //Swap dragged item with full slot
     else if (data.pointerId == -1 && _inventory.inventory[SlotNumber] != null && _gui.isBeingDragged)
     {
         Item itemBeingDragged = _gui.DraggedItem;
         Item itemInSlot       = _inventory.inventory[SlotNumber];
         _inventory.inventory[_gui.DraggedSlotNumber] = itemInSlot;
         _inventory.inventory[SlotNumber]             = itemBeingDragged;
         //Update server
         //Remove items
         _network.RemoveInventoryItem(itemBeingDragged.Slot, itemBeingDragged.Count);
         _network.RemoveInventoryItem(itemInSlot.Slot, itemInSlot.Count);
         //Swap slot numbers
         itemBeingDragged.Slot = SlotNumber;
         itemInSlot.Slot       = _gui.DraggedSlotNumber;
         //Add items
         _network.AddInventoryItem(itemBeingDragged);
         _network.AddInventoryItem(itemInSlot);
         //Clear dragged item
         _gui.DeleteDraggedItem();
     }
     //Right click on non-empty slot
     if (data.pointerId == -2 && _inventory.inventory[SlotNumber] != null)
     {
         _gui.ShowItemOptions(_gui.itemSlots[SlotNumber].GetComponent <RectTransform>(), _inventory.inventory[SlotNumber]);
     }
 }
    //Adds item via below function and notifies database
    public bool AddItemToInventory(Item item)
    {
        bool success = AddItemToInventoryBase(item);

        if (success)
        {
            _network.AddInventoryItem(item);
        }
        return(success);
    }