/// <summary> /// Get linked slot by index /// </summary> /// <param name="index">index that should be in range from 0 to <see cref="LinkedSlotsCount"/> - 1</param> /// <returns>linked inventory slot (may be null or contain null item)</returns> public InventoryLinkedSlotUI GetLinkedSlot(int index) { if (index < 0 || index >= linkedSlotUIs.Length) { Debug.LogError($"Index out of range. index: {index} range:<0; {linkedSlotUIs.Length - 1}>", this); return(null); } InventoryLinkedSlotUI linkedSlotUI = linkedSlotUIs[index]; return(linkedSlotUI); }
/// <summary> /// Try to link InventorySlot to InventoryLinkedSlotUI (each InventorySlot may be linked to only one InventoryLinkedSlotUI) /// </summary> public void TryToLinkSlot(InventoryLinkedSlotUI linkedSlotUI, InventorySlot inventorySlot) { if (linkedSlotUI == null) { return; } // check only for non null slots if (inventorySlot != null) { // check if inventory slot is linked to any other InventoryLinkedSlotUI // and return if so foreach (var linkedSlot in linkedSlotUIs) { if (linkedSlot.LinkedSlot == inventorySlot) { return; } } } // else, link slot linkedSlotUI.LinkedSlot = inventorySlot; }