Exemple #1
0
    public void BeginDrag(ItemDisplayer newDragged)
    {
        if (GetDragged != null)
        {
            EndDrag(EndDragPosition.original);
        }

        GetDragged = newDragged;

        int startingIndex =
            GetDragged.isInventory ?
            GetDragged.itemIndex :
            itemGridPanel.displayersGrid.transform.childCount;

        if (EventSystemModifier.Current.IsUsingMouse)
        {
            GetDragged.transform.SetParent(topLayer);
        }
        else
        {
            GetDragged.SetNavigation(false);
            GetDragged.selectable.Select();
            GetDragged.SetBobbing(true);
        }

        itemGridPanel.BeginDrag(startingIndex);
    }
    public void EndDrag(ItemDisplayer draggedCopy, EndDragPosition endPosition)
    {
        if (draggedMouse)
        {
            emptyPlaceholder.SetParent(emptyPlaceholderStorage);

            if (draggedCopy.isInventory)
            {
                draggedCopy.transform.SetParent(displayersGrid.transform);
            }
        }
        else
        {
            draggedCopy.SetBobbing(false);
            draggedCopy.SetNavigation(true);
            draggedCopy.selectable.Select();
        }

        if (endPosition == EndDragPosition.newPosition)
        {
            var equipment = master.playerEquipment;

            if (draggedCopy.isInventory)
            {
                //this will induce further callbacks which corrects the dragged sibling index
                equipment.Reorder(draggedCopy.itemIndex, draggedSiblingIndex);
            }
            else if ((draggedInside &&
                      //this will induce further callbacks which corrects the position
                      equipment.UnequipArms((Armament.Slot)draggedCopy.itemIndex, draggedSiblingIndex))
                     == false)
            {
                master.equipmentPanel.ResetPosition((Armament.Slot)draggedCopy.itemIndex);
            }
        }
        else if (endPosition == EndDragPosition.original)
        {
            if (draggedCopy.isInventory)
            {
                draggedCopy.transform.SetSiblingIndex(draggedCopy.itemIndex);
            }
            else
            {
                master.equipmentPanel.ResetPosition((Armament.Slot)draggedCopy.itemIndex);
            }
        }
    }