/// <summary>
 ///
 /// </summary>
 /// <param name="item"></param>
 /// <returns>
 /// The address of the inventory slot the item has be placed in. Returns
 /// null if the item was not placed (i.e. inventory is full)
 /// </returns>
 public InventoryAddress Keep(Item item)
 {
     for (int page = 0; page < Storage.GetLength(0); page++)
     {
         for (int row = 0; row < Storage.GetLength(2); row++)
         {
             for (int col = 0; col < Storage.GetLength(1); col++)
             {
                 if (Storage[page, col, row] == null)
                 {
                     Storage[page, col, row] = item;
                     Inbox.Remove(item);
                     return(InventoryAddress.NewStorageAddress(page, col, row));
                 }
             }
         }
     }
     return(null);
 }
Beispiel #2
0
    private void InitializeStorageSlots()
    {
        Vector2 sizeDelta = StorageContent.GetComponent <RectTransform>().sizeDelta;

        sizeDelta.y = GameManager.Instance.Player.Inventory.Storage.GetLength(2) * 74 - 10;
        StorageContent.GetComponent <RectTransform>().sizeDelta = sizeDelta;

        StorageSlots = new StorageSlotController[GameManager.Instance.Player.Inventory.Storage.GetLength(1), GameManager.Instance.Player.Inventory.Storage.GetLength(2)];
        for (int col = 0; col < StorageSlots.GetLength(0); col++)
        {
            for (int row = 0; row < StorageSlots.GetLength(1); row++)
            {
                GameObject newStorageSlot = Instantiate(StorageSlotPrefab, StorageContent.transform);
                newStorageSlot.GetComponent <RectTransform>().anchoredPosition = new Vector2(col * 74, -row * 74);
                InventoryAddress address = InventoryAddress.NewStorageAddress(CurrentStoragePage, col, row);
                newStorageSlot.GetComponent <StorageSlotController>().Initialize(this, address, GameManager.Instance.Player.Inventory.Storage[CurrentStoragePage, col, row]);
                StorageSlots[col, row] = newStorageSlot.GetComponent <StorageSlotController>();
            }
        }
    }