コード例 #1
0
    /// <summary>
    /// Call this method to remove item of EItemType.
    /// if not specified - will delete the oldest item in the inventory.
    /// if there is more than one item of the same type in the inventory,
    /// will remove the "new" one.
    /// </summary>
    /// <param name="itemType"></param>
    public void RemoveItem(CarriableItem_SO.EItemType itemType = CarriableItem_SO.EItemType.Null)
    {
        // If not specified - will delete the oldest item in the list.
        if (itemType == CarriableItem_SO.EItemType.Null)
        {
            _currentItems.RemoveLast();
            Debug.Log("Deleted the last item because nothing else was specified");
            UpdatePassiveStatsManager();
            return;
        }
        var cur = _currentItems.First;

        for (int i = 0; i < _currentItems.Count; i++)
        {
            if (cur != null && cur.Value.GetItemType() == itemType)
            {
                Debug.Log("Removing the item " + cur.Value.GetItemType());
                _currentItems.Remove(cur);
                UpdatePassiveStatsManager();
                return;
            }

            if (cur != null)
            {
                cur = cur.Next;
            }
        }
    }
コード例 #2
0
    /// <summary>
    /// Call this method to find if there is an item
    /// of type EItemType (could be multiple)
    /// </summary>
    /// <param name="itemType"></param>
    /// <returns></returns>
    public bool DoesHaveItem(CarriableItem_SO.EItemType itemType)
    {
        var cur = _currentItems.First;

        for (int i = 0; i < _currentItems.Count; i++)
        {
            if (cur != null && cur.Value.GetItemType() == itemType)
            {
                return(true);
            }

            if (cur != null)
            {
                cur = cur.Next;
            }
        }

        return(false);
    }