Ejemplo n.º 1
0
    public void OnEndDrag(PointerEventData eventData)
    {
        var result = new List <RaycastResult>();

        EventSystem.current.RaycastAll(eventData, result);

        foreach (var item in result)
        {
            //Debug.Log(item);

            if (item.gameObject.TryGetComponent(out InventoryContainer container) && container.ItemSlot.IsEmpty)
            {
                Debug.Log(container);
                if (_loot.CheckLootСompatibility(container.ItemSlot))
                {
                    _currentContainer.ItemSlot.ChangeEmptyStatus(); //освобождаем контейнер из которого перетащили предмет(сундук статус не меняет, он всегда "пуст")
                    transform.SetParent(container.Container);       // назначаем родителем новый контейнер

                    /*if (_currentContainer.ItemSlot is AnySlot) // если контейнер был сундуком, вызываем событие на удаление предмета из содержимого
                     * {
                     *
                     *  //TakenFromChest?.Invoke();
                     *
                     *  Debug.Log(_loot + " TAKEN FROM CHEST");
                     * }*/

                    _currentContainer = container;          // назначаем новый контейнер текущим

                    container.ItemSlot.ChangeEmptyStatus(); // меняем статус контейнера на "занят"(сундук статус не меняет, он всегда "пуст")

                    /*if (_currentContainer.ItemSlot is AnySlot)  // если новый контейнер - сундук, вызываем событие на добавление предмета
                     * {
                     *
                     *  //PuttedIntoChest?.Invoke();
                     *
                     *  Debug.Log(_loot + "PUTTED INTO CHEST");
                     * }*/
                    return;
                }
            }
            transform.SetParent(_previousParent);
        }
    }