Encounter / Assets / Scripts / InventoryManagement / DropBox.cs
DropBox.cs
Raw
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

/// <summary>
/// Handles drop locations for the draggable items
/// </summary>
public class DropBox : MonoBehaviour, IDropHandler
{
    public enum DropLocations
    {
        ShopStock,
        ShopInventory,
        LootStock,
        LootInventory,
        ActiveItemNecklace,
        ActiveItemRingOne,
        ActiveItemRingTwo,
        ActiveItemHelmet,
        ActiveItemChest,
        ActiveItemBoots,
        ActiveItemWeapon,
        ActiveItemSecWeapon,
        ActiveItemRelic,
        GeneralItemInventory
    }

    [Header("Purpose Indicators")]
    public DropLocations Type;

    private readonly Vector2Int ShopInventoryCellSize = new Vector2Int(45, 55);
    private readonly Vector2Int ShopStockCellSize = new Vector2Int(65, 80);
    private readonly Vector2Int GeneralCellSize = new Vector2Int(80, 80);
    private readonly Vector2Int LootInvenCellSize = new Vector2Int(75, 85);
    private readonly Vector2Int LootStockCellSize = new Vector2Int(55, 75);

    public void DetectItemUISize(DropLocations type)
    {
        this.Type = type;
        GridLayoutGroup gridLayout = GetComponent<GridLayoutGroup>();
        if (type == DropLocations.ShopInventory)
            gridLayout.cellSize = ShopInventoryCellSize;
        else if (type == DropLocations.ShopStock)
            gridLayout.cellSize = ShopStockCellSize;
        else if (type == DropLocations.GeneralItemInventory)
            gridLayout.cellSize = GeneralCellSize;
        else if (type == DropLocations.LootInventory)
            gridLayout.cellSize = LootInvenCellSize;
        else if (type == DropLocations.LootStock)
            gridLayout.cellSize = LootStockCellSize;
    }
    public void OnDrop(PointerEventData eventData)
    {
        try
        {
            GameObject droppedItem = eventData.pointerDrag;
            droppedItem.GetComponent<DraggableItem>().SetParentDrag(transform);
        }
        catch
        {
            return;
        }
    }
}