Пример #1
0
 protected virtual void Awake()
 {
     if (dragDrop == null)
     {
         dragDrop          = gameObject.GetComponent <SlotDragAndDrop>();
         dragDrop.dragable = false;
     }
 }
Пример #2
0
 private void DropOnBin(SlotDragAndDrop draggued)
 {
     //Only if object come from inventory directly
     if (draggued.gameObject.CompareTag("InventorySlot"))
     {
         ItemStack itemStackToDelete = draggued.gameObject.GetComponent <InventorySlot>().ItemStack;
         Inventory.instance.Remove(itemStackToDelete);
     }
 }
Пример #3
0
    private void DropOnEquipment(SlotDragAndDrop draggued)
    {
        // item
        Item item = draggued.gameObject.GetComponent <InventorySlot>().ItemStack.item;

        if (item.GetType() == typeof(Equipment))
        {
            //Equip it
            item.Use();
        }
    }
Пример #4
0
    private void DropHotbarOnInventory(SlotDragAndDrop draggued)
    {
        InventorySlot hotbarSlot = draggued.GetComponent <InventorySlot>();

        //emptySlot
        if (!dragable)
        {
            Hotbar.instance.Remove(hotbarSlot);
        }
        else
        {
            Hotbar.instance.AddItem(GetComponent <InventorySlot>().ItemStack, hotbarSlot);
        }
    }
Пример #5
0
    private void DropOnHotbar(SlotDragAndDrop draggued)
    {
        InventorySlot dragguedSlot = draggued.GetComponent <InventorySlot>();
        InventorySlot thisSlot     = GetComponent <InventorySlot>();

        //hotbar to hotbar, just switch object position
        if (draggued.gameObject.CompareTag("hotbarSlot"))
        {
            Hotbar.instance.SwitchSlot(thisSlot, dragguedSlot);
        }
        else if (draggued.gameObject.CompareTag("InventorySlot"))
        {
            Hotbar.instance.BindItemInventoryWithSlot(dragguedSlot.ItemStack.item, thisSlot);
        }
    }
Пример #6
0
    public virtual void ClearSlot()
    {
        itemStack = null;

        icon.sprite  = null;
        icon.enabled = false;

        stacks.text    = null;
        stacks.enabled = false;
        if (dragDrop == null)
        {
            dragDrop = gameObject.GetComponent <SlotDragAndDrop>();
        }
        dragDrop.dragable = true;
        dragDrop.dragable = false;
    }
Пример #7
0
//    private void DropEquipmentOnInventory(SlotDragAndDrop draggued)
//    {
//        EquipmentSlotScript equipmentSlot = draggued.gameObject.GetComponent<EquipmentSlotScript>();
//        ItemStack itemStack = GetComponent<InventorySlot>().ItemStack;
//
//        if (itemStack != null && itemStack.item.GetType() == typeof(Equipment))
//        {
//            // Equip the equipment of the received slot only if it's the same type equipmentSlot of the draggued object
//            // Correct the bug: drop a sword on helmet, then the sword isn't unequip and helmet is equip
//            Equipment equipment = (Equipment) itemStack.item;
//            if (equipment.equipSlot == equipmentSlot.equipmentSlot)
//            {
//                itemStack.item.Use();
//                return;
//            }
//        }
//
//        equipmentSlot.Unequip();
//    }

    private void SwitchInventoryItems(SlotDragAndDrop draggued)
    {
        // if empty, move object to the end of the list else, switch item place
        ItemStack itemStackDraggued = draggued.GetComponent <InventorySlot>().ItemStack;

        //emptySlot
        if (!dragable)
        {
            Debug.Log("Is Empty slot");
            Inventory.instance.MoveItemToLastIndex(itemStackDraggued.item);
        }
        else
        {
            Debug.Log("Is not Empty slot");
            ItemStack itemStack = GetComponent <InventorySlot>().ItemStack;
            Inventory.instance.SwitchItemInInventory(itemStack.item, itemStackDraggued.item);
        }
    }
Пример #8
0
    public virtual void AddItem(ItemStack newItem)
    {
        itemStack = newItem;


        //Debug.Log(itemStack.item.icon.name);
        icon.sprite = itemStack.item.icon;
        //Debug.Log(icon.sprite.name);

        icon.enabled = true;

        UpdateText();
        stacks.enabled = true;
        if (dragDrop == null)
        {
            dragDrop = gameObject.GetComponent <SlotDragAndDrop>();
        }
        dragDrop.dragable = true;
    }
Пример #9
0
    // d.pointerDrag is the object that was dragged
    public void OnDrop(PointerEventData d)
    {
        // one mouse button is enough for drag and drop
        if (dropable && d.button == button)
        {
            // was the dropped GameObject a UIDragAndDropable and was it dragable?
            // (Unity calls OnDrop even if .dragable was false)
            SlotDragAndDrop dropDragable = d.pointerDrag.GetComponent <SlotDragAndDrop>();
            if (dropDragable != null && dropDragable.dragable)
            {
                // only do something if we didn't drop it on itself. this way we
                // don't have to ignore raycasts etc.
                // message is sent to drag and drop handler for game specifics
                if (dropDragable != this)
                {
                    //Switch depending on tag of slot receiver
                    switch (gameObject.tag)
                    {
                    // if the slot is Equipment slot, try to equip if it's an equipment
                    case "EquipmentSlot":
                        DropOnEquipment(dropDragable);
                        break;

                    case "InventorySlot":
                        DropOnInventory(dropDragable);
                        break;

                    case "hotbarSlot":
                        DropOnHotbar(dropDragable);
                        break;

                    case "BinSlot":
                        DropOnBin(dropDragable);
                        break;
                    }
                }
            }
        }
    }
Пример #10
0
    private void DropOnInventory(SlotDragAndDrop draggued)
    {
        /* if it's an inventory slot,
         * - we drag an equipement: unequip equipment if this slot is not empty, reequip only if it's an equipment in this slot
         * - we drag inventory slot: switch both emplacement exept if this slot is empty.
         * - we drag hotbar slot: clear hotbarSlot if empty, else hotbar slot is link on this slot
         */
        switch (draggued.gameObject.tag)
        {
        case "EquipmentSlot":
//                DropEquipmentOnInventory(draggued);
            break;

        case "InventorySlot":
            SwitchInventoryItems(draggued);
            break;

        case "hotbarSlot":
            DropHotbarOnInventory(draggued);
            break;
        }
    }