Ejemplo n.º 1
0
    //items slots
    protected virtual void onBeginDrag(BasicItem _item, PointerEventData _eventData)
    {
        draggableItem = _item;
        //я не могу перетаскивать объекты которых нету
        iCanDrag = !draggableItem.IsEmpty();

        if (!iCanDrag)
        {
            return;
        }
        isDrag = true;


        bufferItem.transform.position = _eventData.pointerCurrentRaycast.worldPosition;
        bufferItem.Item = draggableItem.Item;

        indexTake = slots.FindIndex(x => x.currentItem == draggableItem);

        RemoveItem(draggableItem.Item);
        draggableItem.Dispose();

        NormalizedContainerBySlots();

        BasicSlot slot = _item.GetComponentInParent <BasicSlot>();

        indexThrow = slots.FindIndex(x => x == slot);
        slots[indexThrow].SetActiveRightHover(true);

        InventoryOverseer._instance.from = this;        //от куда взял
    }
Ejemplo n.º 2
0
    protected virtual void EndDrag(BasicItem _item, PointerEventData _eventData)
    {
        if (!iCanDrag)
        {
            return;
        }
        InventoryOverseer._instance.to = this;        //куда положил

        if (InventoryOverseer._instance.Verify())     //если этот контейнер тот же от куда взяли
        {
            if (indexThrow != -1 && !isEmpty())       //сдвинули
            {
                if (!slots[indexThrow].IsEmpty())
                {
                    InsertItemTo(bufferItem.Item);                    //что бы всё время не добавлять в конец
                }
                else
                {
                    AddItem(bufferItem.Item);
                }
            }
        }

        InventoryOverseer._instance.Dispose(); //если не освобождать, то удаление старого предмета не будет и произойдёт добавление его в конец
        bufferItem.Dispose();                  //освобождаем буффер

        indexThrow = -1;
        isDrag     = false;

        HightLightOff();
    }
Ejemplo n.º 3
0
 protected override void OnPointerClick(BasicItem _item, PointerEventData _eventData)
 {
     if (!isDrag)
     {
         if (!_item.IsEmpty())              //если слот не пуст то удаляем объект и нормализуем контэйнер
         {
             RemoveItem(_item.Item);
             _item.Dispose();
             NormalizedContainerBySlots();
         }
     }
 }