The InventorySystem - C# - Unity5 - New UI System (uGUI) - Extremely extensible!

I launched a new Unity 5 Asset store package, an event driven Inventory system with loads of features build on Unity’s new UI system.

>> Asset store <<
>> The demo <<

In development:
Vendor system (NPC buying selling + buy back)
Crafting system with blueprints and categories. (Crafting, tailoring, etc…)

Current features:
Written in C#
Mobile ready
Fully customizable
Looting
Multiple inventories (Restrict inventory to categories and items of the category will be placed in it).
Context menu (Right click item menu)
Using / equipping items
Skillbar with references
Bank storing
Unique item properties
Stacking items
Item categories with category cooldown
Unstacking items
Drop dialog
Unstack dialog
Item toolips
Extending with bags (PRO ONLY!)
Cleanup inventory (PRO ONLY!)
Editor - Item creator
Editor - Category creator
Editor - Rarity creator
Code - Event driven design
Code - Extremely extensible
Code - Well documented
Code - uGUI (Unity GUI)
Design - Complete RPG UI design (PRO ONLY!)

Want to request a feature or report a bug? Please go to https://bitbucket.org/jorisshh/inventorysystemv2/issues

Don’t want to miss a thing?
Stay updated through the mailing list.

Completely Unity 5 ready.

The PRO package is now also live at https://www.assetstore.unity3d.com/en/#!/content/31226 for those who want collection sorting (cleaning the inventory / bank (or any other collection), by sorting the items and re-stacking) + extensible collections by adding bags & a complete UI design (PSD).

I hope this will work also on mobiles with drag and drop.
Is it easy to skin it?

I’ve added mobile support to the InventorySystem including unstacking and custom triggers for mobile that can be directly modified from the editor (See image below). (Package should be live in asset store in a few days)

To answer your second question, yes the UI is completely skinable, items are placed inside the container, you can use uGUI’s Grid / Horizontal / Vertical containers, or if you want more flexibility define the collection manually and create a fully flexible UI. And not only the layout can be modified, textures, icons, everything you can think of can be modified.

Even the GameObjects created with the ItemManager can be edited and support custom components to allow full control.

Hope this clears things up :).

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.

do you have a mobile demo ? ( without drag and drop )

Do you mean an APK to try on a mobile device / emulator?

not necessary a webbuild would be fine, but currently there is no inventory that have “mobile support” they all support mouse input for drag and drop, i feel mobile inventory works better with buttons like [loot][equip][drop] etc…

Also how do you manage item types, bonus stats? for example can i have guns weapons type with their own stats like dps, fire rate, bonus health, an other item that we can only loot/drop with no use and no stats, or having vehicle with their own stats, is it possible?

I suppose you mean a context menu, something like Guild wars 2 (See screenshot)?

This is currently not supported, but would be quite easy to create. Methods inside the InventorySystem can be overriden.
The system uses a wrapper to separate the UI specific code from the actual inventory item logic. This allows you to create a new class lets call it “InventoryUIContextWrapper” which will extend the InventoryUIItemWrapper. Inside the class you can override the OnPointerUp method and add your own functionality such as a context menu.
If this is a commonly requested feature I can build this into the core. Features and bugs can be reported / requested here: https://bitbucket.org/jorisshh/inventorysystemv2/issues

For your second question, if I understand correctly, you want to assign specific stats to items? One way to do it would be to add a bunch of standard stats like addHealth addMana, etc. When the value is 0 you simply don’t display it inside the UI, this allows a lot of simple editor tweaking and will likely save you a lot of time.

If you however want to add very specific variables to an object you can create a new item type. Simply create a new class, extend from InventoryItemBase and implement all the variables you want / override the methods you want.

Tooltip info is retreived through the GetInfo() method, which you can override, so you can manage the information shown per item type.

If you’re looking for the regular demo try this one.

Hope this helps.

If you like I can create a bit of sample code to implement a simple context menu, it can be done in ~50 lines of code.

thanks that would be nice.

for the Stats i used one other inventory assets(master inventory) that managed it like that: the stats are only data defined in inspector, so i could add any stat to any type of object, which make object creation really powerful

only thing is its not easy to extend it for mobile, and even having 1 inventory = one type of items was not possible with this asset for example player inventory, quest inventory

Alright, I’ve started the creation on the metadata (adding the any stat to any item), this shouldn’t take more than a day. For the context menu, I’ll just implement it inside the core, it isn’t to much work and likely a feature that more people would like.

I’ve build the context menu into the core:

The context menu can be manipulated per item type. You can of course disable the context menu and use the system without it.
As for the metadata, I’m working on it :slight_smile:

And the metadata is also done. Decided to call them item properties.

Properties can be added to any item type and you can add as many as you like. If Show? is toggled the item will be shown in the UI tooltip. By default the properties are shown at the bottom but you can of course override this in code and place them wherever you like.

Properties can also be retrieved through code, I added some convenience properties to cast the editor strings to useful datatypes.

Should be updated in the asset store in a few days.

I will likely start production on the NPC buying & selling with buy back in the upcoming week, as this is a commonly requested feature.

If anyone wants to make specific requests regarding the buying / selling, please do so now :).

thats all great, do you have a road map ? like a simple crafting system where we also have a list of blueprint that are item, we can add them to bp list by using them, and craft is simple like item B = item A +C, is it possible?

I’ve decided to build in the NPC system as well as the crafting system as these are the most requested features. You can expect these features by the end of next week.

I’ll hold off on the rest of the features for now, and see what will be requested by the community.

Do you have any videos of this in action? Can you choose the layout of the inventory? For example: I want 2 columns of 8 rows, on the right side of the screen, or want 1 row, with 10 columns along the bottom of the screen. Can the size of the boxes be changed? How it appears? Can it slide in from off screen, or just pop up?

Everything you just described is possible and very easy to do. I’ll be sure to record a video once I get home, showing all these features in detail.

i just tested it and im a bit disappointed on how it is currently not generic at all and binded to a specific game type.

  • we cant edit properties of items right now like you shown on your script, items have stats hard written in script, it would be nice to have an inspector tab for Attributes, then we can add any of these attributes+ stats)

-your consumable have use direct call of function like add health add mana, but what if we dont have those but other stats? it would be better to use something like sendMessage for this like “buffStatxx” float amount, float length. then we decide where we send this

-you use gold for currency, but what if we use something else and use more than one currency? it would be good to have an inspector to set data like this too.it should not be on InventoryUI but you should have a component for this like CurrencyUI that we could add to any inventory and define its position

-we can add allowed categories to an inventory ( thats good), but we cant have more than one inventory, else it bug, so its an useless features as we cant loot other items

-we must have the scene opened with the inventory inside it to edit it, else:
There is no ItemManager in the scene, attach an ItemManager script to a gameObject.
UnityEngine.Debug:LogError(Object)

-if i delete all items/ categories and try to add mine i will have error when i click create new item
InvalidOperationException: Operation is not valid due to the current state of the object
System.Collections.Stack.Peek () (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections/Stack.cs:321)