InventoryItemDragHandler

 avatar
user_3183455
csharp
a year ago
1.6 kB
7
Indexable
using CuongMono.Item.Inventory;
using UnityEngine;
using UnityEngine.EventSystems;
 
namespace CuongMono.Item
{
    public class InventoryItemDragHandler : ItemDragHandler, IPointerClickHandler, IPointerDownHandler
    {
        [Header("Inventory")]
        [SerializeField] protected Inventory.Inventory inventory;
        public override void OnPointerClick(PointerEventData eventData)
        {
         
        }
        private void UpdateUI()
        {
            this.itemSlotUI?.UpdateUI();
            this.cursorHolder?.InventoryItemSlotUI?.UpdateUI();
        }
        public void OnPointerDown(PointerEventData eventData)
        {
            if (this.cursorHolder.InventoryItemSlotUI.ItemSlot.Item == null &&
                    this.inventory.itemContainer.itemSlots[this.SlotIndex].Item == null) return;
            if (eventData.button == PointerEventData.InputButton.Left)
            {
                this.cursorHolder.InventoryItemSlotUI.ItemSlot =
                    (InventoryItemSlot)this.inventory.itemContainer.SwapItemLeftClick(this.cursorHolder.InventoryItemSlotUI.ItemSlot,
                    this.SlotIndex);
                this.UpdateUI();
            }else if (eventData.button == PointerEventData.InputButton.Right)
            {
                this.cursorHolder.InventoryItemSlotUI.ItemSlot =
                    (InventoryItemSlot)this.inventory.itemContainer.SwapItemRightClick(this.cursorHolder.InventoryItemSlotUI.ItemSlot,
                    this.SlotIndex);
                this.UpdateUI();
            }
        }
 
    }
}
Editor is loading...
Leave a Comment