public InventorySlotUI FindNeighbours(UIMoveDirection dir)
    {
        InventorySlotUI s = null;

        if (dir == UIMoveDirection.Down)
        {
            if (selectable.FindSelectableOnDown().TryGetComponent <InventorySlotUI>(out InventorySlotUI outSlot))
            {
                s = outSlot;
            }
        }
        else if (dir == UIMoveDirection.Up)
        {
            if (selectable.FindSelectableOnUp().TryGetComponent <InventorySlotUI>(out InventorySlotUI outSlot))
            {
                s = outSlot;
            }
        }
        else if (dir == UIMoveDirection.Right)
        {
            if (selectable.FindSelectableOnRight().TryGetComponent <InventorySlotUI>(out InventorySlotUI outSlot))
            {
                s = outSlot;
            }
        }
        else if (dir == UIMoveDirection.Left)
        {
            if (selectable.FindSelectableOnLeft().TryGetComponent <InventorySlotUI>(out InventorySlotUI outSlot))
            {
                s = outSlot;
            }
        }
        return(s);
    }
Esempio n. 2
0
    private void GetNextSlot(UIMoveDirection direction)
    {
        InventorySlotUI selectableNeighbour = slots[currentSlotIndex].FindNeighbours(direction);

        if (selectableNeighbour != null)
        {
            int previousSlotIndex = currentSlotIndex;
            for (int i = slots.Count - 1; i >= 0; i--)
            {
                if (slots[i] == selectableNeighbour)
                {
                    currentSlotIndex = i;
                }
            }
            MoveCursor(previousSlotIndex, currentSlotIndex);
        }
        else
        {
            Debug.Log("Neighbour not found!");
        }
    }