コード例 #1
0
    public void AddItem(Item itemToAdd, bool isExisting = false)
    {
        if (itemToAdd.Type == ItemTypes.Potion)
        {
            var potion = ScriptableObject.CreateInstance <Potion>();
            potion.Sprite = itemToAdd.Sprite;
            potion.Id     = itemToAdd.Id;
            potion.Type   = itemToAdd.Type;
            potion.Effect = _effectFactory.GeneratePotionEffect();
            InventoryItems.Add(potion);

            TriggerInventoryItemAdded();
        }
        if (itemToAdd.Type == ItemTypes.Helmet)
        {
            var helmet = ScriptableObject.CreateInstance <Helmet>();
            helmet.Sprite = itemToAdd.Sprite;
            helmet.Id     = itemToAdd.Id;
            helmet.Type   = itemToAdd.Type;
            if (isExisting)
            {
                var existingItem = itemToAdd as Helmet;
                if (existingItem != null)
                {
                    helmet.Attribute = existingItem.Attribute;
                }
            }
            else
            {
                helmet.Attribute = _attributeFactory.GenerateAttribute();
            }

            InventoryItems.Add(helmet);

            TriggerInventoryItemAdded();
        }
    }