示例#1
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);
    }
示例#2
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);
    }
示例#3
0
    private void InventoryController_ActiveSlotChanged(object sender, SlotStateChangeEventArgs e)
    {
        if (HandLocation.childCount > 0)
        {
            Destroy(HandLocation.GetChild(0).gameObject);
        }

        if (e.InventoryObject?.GetComponent <Equipabble>() != null)
        {
            EquipItem(e.InventoryObject);
        }
    }
示例#4
0
 private void InventoryController_ItemPickedUp(object sender, SlotStateChangeEventArgs e)
 {
     AddItem(e.InventoryObject, e.SlotIndex);
 }
示例#5
0
 private void InventoryController_ActiveSlotChanged(object sender, SlotStateChangeEventArgs eventArgs)
 {
     UnhighlightSlot(activeSlot);
     HighlightSlot(eventArgs.SlotIndex);
     activeSlot = eventArgs.SlotIndex;
 }