An in-depth look about customization
Collections:
All windows that can contain items are called “Collections”. A collection is basically a glorified array that holds all the items and allows stacking, merging, swapping, etc. The basic collection (class ItemCollectionBase) has some default settings that allow quick and easy tweaking without having to dive into the code.
- useReferences - This doesn’t directly store the items inside the collection. When an item is placed inside the collection a reference is created.
- InitialCollectionSize - This sets the size of the collection when the game starts. You can change this at run-time but be sure to instantiate UI elements accordingly (check documentation for more info).
- container - The container is the parent of all inventory slots. You can easily create a grid / horizontal or vertical layout by using uGUI’s buildin automatic layouts.
- onlyAllowItemsOfType - This allows you to block items to a certain type. For example when extending the inventory there are 4 slots to place bags, by using the onlyAllowItemsOfType the collection can easily be limited to items of type bag. Example: This can also be useful if you want to limit a bag to only allow potions or consumable goods.
- canDropFromCollection - Can you drop directly from the collection? Ignored if useReferences is enabled.
- canUseFromCollection - Can an item be used directly from the given collection? Example: Can you use a potion directly from the bank?
- canDragInCollection - Can items be re-arranged inside the collection? Disable if you want to have a static collection that the user cannot modify. For example a loot window.
- canPutItemsInCollection - Can the user put items inside the collection or is it read only?
- manuallyDefineCollection - If you don’t want your collection to be auto-generated you can manually define it inside the Unity inspector.
Interface:
The interface is setup inside uGUI and is therefore completely adjustable to your needs. If you don’t want to use certain elements, simply leave them empty, the system will handle the rest :).
Tooltips
Tooltips are shown when the user hovers over an item icon. These tooltips can be modified per item type. For example a consumable item might want to show how much health it regenerates while a weapon would likely want to show how much damage it deals.
By default the tooltip shows some basic information, but you are in no way forced to use these.
ConsumableInventoryItem (example item in project)
public override LinkedList<InfoBox.Row[]> GetInfo()
{
var basic = base.GetInfo();
basic.AddFirst(new InfoBox.Row[]{
new InfoBox.Row("Restore health", restoreHealth.ToString(), Color.green, Color.green),
new InfoBox.Row("Restore mana", restoreMana.ToString(), Color.green, Color.green)
});
return basic;
}
Each InfoBox.Row is treated as a row inside the UI, each row is separated by a euh… separator. Obviously this is also modifiable.
Inside the UI element you can define the layout and design of the tooltip.
Extending the code
(Almost) all classes inside the InventorySystem are marked partial. This means that if you create a class with the exact same name you can add functionality to the core features all without overriding core code. The compiler will auto. merge the files together. I highly encourage you to use this method, because it is the safest way to avoid problems with updates and conflicts.
Example: So how does it work?
The core system has 5 default item types.
Let’s say for the sake of this sample that we want to add extra functionality to the Consumable item type.
All we have to do is create a new C# class and name it “public partial class ConsumableInventoryItem”. Check the example below for a simple implementation.
public partial class ConsumableInventoryItem
{
public int restoreDexterity;
public void DoSomeAction()
{
}
}
All consumable items now contain a variable restoreDexterity and have an extra method DoSomeAction().
This works with (almost) all core classes of the InventorySystem.
Of course you also have the ability to inherit and override core functionality by using the override keyword in you classes.