Serialized Item Database Example Part 2!
Objective: Add and Array to our item database and add details to items.
We have created an item base and we have learned to serialize these items. The next logical step is to turn add an array so we can quickly and easily add more items to our games. We can populate these items through the coder.
In the Start method we are creating the dagger, fishing pole, and food. 3 items in 3 different ways. if you pressed play on the editor the fields will be populated.
Alternatively, we could remove everything in the item database.
If we wanted to, since the item class is serialized, we can see it in the inspector which means we can add an array to the item database.
Now the inspector will show an array for item, and we can easily select how many items are in our game.
Since the name is a string when you name it, the element will change to the item name you enter.
This allows you or a designer to go through and create items for your game. They add the amount of items they need and fill our the details.
As a bonus if you wanted to you could even come down into your item class and say you wanted to add more details to your items.
That’s how you interact with these items. If you wanted to interact through the array of items, you could just grab an item. If you wanted to print out the first item, you would use this debug log code.
That’s all there is to serializing a database you create for your game. With this set up adding assets to your game can be done quicker and more precise then without. Don’t be afraid to experiment with your code, and I’ll see you in the next tutorial.