コード例 #1
0
ファイル: Inventory.cs プロジェクト: Awesome-MQP/Storybook
    /// <summary>
    /// Adds an item to the inventory.
    /// </summary>
    /// <param name="item">The item to add to the inventory.</param>
    /// <param name="index">The index to put the item in.</param>
    /// <returns>True if the item could be added, otherwise false.</returns>
    public virtual bool Add(Item item, int index)
    {
        if (index < 0 || index >= m_items.Length || m_items[index] != null || !CanAddItem(item, index))
            return false;

        InventoryAddCommit addCommit = new InventoryAddCommit(m_commitCounter++, (short)index, item);
        bool wasAdded = _PushCommit(addCommit);
        if (wasAdded)
        {
            item.PickedupWithInventory(this, index);
        }
        return wasAdded;
    }