How do I add this to my game ?
There are 2 main ways you can add the Inventory Engine to your game :
- the fast way is to open one of your scenes, drag and drop the PixelRogueRoom1 demo scene into it, drag and drop elements from it into your scene, and remove it. The elements you’ll want to drag and drop that way are the Inventories and InventoryCanvas objects. The Inventories hold the inventory data, and the InventoryCanvas contains everything you need to interact with it. You’ll probably want to modify, rename and reorganize its contents to suit your needs.
- the other way, and the recommended one, is to read through this documentation (it’s not that long) to find out how each components work, and how to best customize them to suit your own needs.
- if you decide to get rid of demo elements, such as the InventoryDemoGameManager, make sure you implement their behaviors somewhere in your own classes!
It’s of course recommended to read the documentation to understand how things work, but if you want a quick start, you can follow these steps :
- fresh install of Inventory Engine v3.0 on 2019.4.37f1 LTS
- create a new, empty scene, name it MyTestScene
- in that scene, add a Cube, on its BoxCollider, isTrigger:true
- add an ItemPicker comp to it, Item:Apple, DisableObjectWhenDepleted:true
- add a Sphere to the scene, add a Rigidbody to it, isKinematic:true, set its Tag to Player
- add a new empty object, name it RogueMainInventory, add an Inventory comp to it, ContentSize: 24, Persistent:false
- drag a UICamera prefab (from the Demos/PixelRogue/Prefabs folder) into the scene, disable its Armor, Weapon and Bomb inventory displays (as we only have the Main inventory in our scene)
- press play in the editor, in scene view, select the sphere, move it on top of the cube to pick the item
- press I to open the inventory
Alternative quick start
Here are alternative steps, slightly more advanced, that will show you how to setup an inventory display and create an item from scratch :
- fresh install of CE v8.0 on 2019.4.40f1
- create a new, empty scene
- add an empty, name it MainInventory, add an Inventory comp to it, Persistent:false
- add a Canvas, add an empty child to it, add an InventoryDisplay comp to it, NbOfRows:1, NbOfColumns:3, press the auto setup button
- create a new Resources/Items/ folder, in it create a new BaseItem asset, name it MyApple, ItemID:MyApple, Icon:IconApple
- add an empty at 0,2,0, add a sprite renderer to it, set its Sprite to Adventurer_0, set its Tag to Player, add a BoxCollider2D to it, and a Rigidbody2D, BodyType:Kinematic
- add an empty at 5,2,0, add a sprite renderer to it, set its Sprite to AdventurerItems_Apple, add a box collider 2D, isTrigger:true, add an ItemPicker, Item:Apple, DisableObjectWhenDepleted:true
- press play, select the adventurer in scene view, drag it over the apple picker, notice an apple gets added to your inventory and to its display :
As is good practice, the engine uses assembly defintions. This separates code nicely, and improves compile times. But that also means that the engine scripts won’t “see” any script outside of their assembly definitions. That’s why it’s encouraged to extend scripts instead of modifying them directly. If you really want to modify core classes instead of extending them, and need access to external APIs, you can either edit the assembly definitions to add access to them (dirty), or remove all assembly definitions (very dirty).