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); }
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); }
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); } }
private void InventoryController_ItemPickedUp(object sender, SlotStateChangeEventArgs e) { AddItem(e.InventoryObject, e.SlotIndex); }
private void InventoryController_ActiveSlotChanged(object sender, SlotStateChangeEventArgs eventArgs) { UnhighlightSlot(activeSlot); HighlightSlot(eventArgs.SlotIndex); activeSlot = eventArgs.SlotIndex; }