Example #1
0
    public bool TryPickupItem(GameObject groundItem)
    {
        if (EmptySlots <= 0 || groundItem == null)
        {
            return(false);
        }

        int inventoryIndex = System.Array.IndexOf(items, null);

        items[inventoryIndex] = groundItem;
        var eventArgs = new SlotStateChangeEventArgs()
        {
            InventoryObject = groundItem,
            SlotIndex       = inventoryIndex
        };

        ItemPickedUp?.Invoke(this, eventArgs);
        if (inventoryIndex == ActiveSlot)
        {
            ActiveSlotChanged?.Invoke(this, eventArgs);
        }

        groundItem.SetActive(false);
        return(true);
    }
Example #2
0
    public void ScrollItem(CallbackContext ctx)
    {
        if (!ctx.performed)
        {
            return;
        }

        short scrollDirection = (short)(ctx.ReadValue <float>() > 0 ? 1 : -1);

        ActiveSlot += scrollDirection;
        if (ActiveSlot >= TotalSlots)
        {
            ActiveSlot = 0;
        }
        else if (ActiveSlot < 0)
        {
            ActiveSlot = TotalSlots - 1;
        }

        SlotStateChangeEventArgs eventArgs = new SlotStateChangeEventArgs()
        {
            InventoryObject = items[ActiveSlot],
            SlotIndex       = ActiveSlot
        };

        ActiveSlotChanged?.Invoke(this, eventArgs);
    }
Example #3
0
 public void SetActiveSlot(InventorySlot inventorySlot)
 {
     _activeSlot = inventorySlot;
     if (inventorySlot != null)
     {
         ActiveSlotChanged?.Invoke(inventorySlot, null);
     }
 }