예제 #1
0
    public void AddTrinket(Trinket trinket)
    {
        if (CurrentCapacity < MaxCapacity)
        {
            var freeRow   = InventoryRows.Find(row => row.HasEmptySlot);
            var emptySlot = freeRow.InventorySlots.Find(slot => slot.HasItem == false);
            freeRow.ItemAdded();
            emptySlot.CreateItem(trinket);
            CurrentCapacity++;
            RealmInventory.Trinkets.Add(trinket);
        }
        else
        {
            var newRow = AddRow();
            newRow.InventorySlots[0].CreateItem(trinket);
            newRow.ItemAdded();
            CurrentCapacity++;
            RealmInventory.Trinkets.Add(trinket);
        }

        if (CurrentCapacity == MaxCapacity)
        {
            AddRow();
        }
        UpdateWindow();
    }
    private void RealmInventoryRowEmptied(int rowNumber)
    {
        if (rowNumber > 3 && rowNumber == InventoryRows.Count)
        {
            for (int i = rowNumber; i > 3; i--)
            {
                if (InventoryRows[i - 1].HasItems)
                {
                    break;
                }

                InventorySlots.RemoveAll(slot => InventoryRows[i - 1].InventorySlots.Contains(slot));
                Destroy(InventoryRows[i - 1].gameObject);
                MaxCapacity -= InventoryRows[i - 1].SlotCount;
                InventoryRows.RemoveAt(i - 1);
            }
        }
    }
    private InventoryRow AddRow()
    {
        InventoryRow newRow = Instantiate(rowTemplate);

        newRow.Initialize(this);
        newRow.RectTransform.SetParent(trinketBox, false);
        InventoryRows.Add(newRow);
        InventorySlots.AddRange(newRow.InventorySlots);

        newRow.RowNumber        = InventoryRows.Count;
        MaxCapacity            += newRow.SlotCount;
        newRow.EventRowEmptied += RealmInventoryRowEmptied;

        for (int j = 0; j < newRow.SlotCount; j++)
        {
            newRow.InventorySlots[j].EventDropIn  += RealmInventorySlotDropIn;
            newRow.InventorySlots[j].EventDropOut += RealmInventorySlotDropOut;
        }
        return(newRow);
    }