Item

Item

The item is a game object that is bound to an ItemDefinition. Items are prefabs that can easily be instantiated in the scene with different components.

Image

The demo has a Consumable Item and Equippable Item types. There are two main function Use and drop. Use is meant to be overridden by you to do exactly what you want when the item is used.

public interface IItem
{
    ItemDefinition ItemDefinition { get; }
    void Use(Inventory itemInventory);
    void Drop(Inventory itemInventory, int amount);
}

When items are equipped they can be used with item actions.

public interface IItemAction
{
    bool CanUse { get; }
    void Use(IItem item, IItemUser itemUser);
}

Item Actions are used in the demo to swing attack with the pickaxe or to throw a snowball. The SwingAttack and ThrowAttack scripts inherit the ItemActionComponent class.