So in my hand-rolled inventory system, slots can have items, both GUI elements, dragged into them, and the slot can use PlayerPrefs to “remember” what and how many of an item occupied it.
Player drags item into slot
The slot creates a PlayerPrefs entry, unique to that slot, which
remembers the ID of the item
It does the same for the amount of the item.
If the slot becomes empty, the slot saves itself as being empty.
- All the slots do this independently, so when the game is
reloaded, each slot simply accesses
one playerprefs entry to re-occupy
itself with / load the item back in.
So, since that slot is already in the scene (unlike items, which are obtained in the game) when the game starts, playerprefs plus some scripting can put the item back in the slot, or “load” our inventory.
I.E., we are saving and loading the item based on that logic.
However, I’ve been trying to move from a “slots on a grid” model to more of an “items in a list” model.
The difference there, is that the slots won’t be there in the first place, rather I will be needing to save information about a list of just the items.
So, My first thought/ option:
Use XML to record which items and how many of them are in the player inventory, which is displayed in a list of just the items’ draggable / interactive UI elements.
But, since I have never messed with XML data serialization, I need opinion from someone who has! Before I go breaking all my code and stuff, you know?
Here is where I imagine myself running into problems:
The player might “lose” an item, any number of ways, in the game!
Will it be easy to remove the entry for that specific item in the XML file?
Or will I have to be rewriting the entire file every time a change occurs in the inventory?
My second option, instead of XML:
Continue to use PlayerPrefs, but disable / hide the “slot” until there is an item actually in it…This way, the items are already being saved in their correct slot, and the feeling of it being a scrollable list of just the items they have can be maintained (they don’t have to scroll through empty slots.)
I would prefer to use XML, but only if I can get a validation that it is appropriate here, from someone who maybe has done similar…So what do you think, and what experience do you have with this kind of problem? Should I use XML or continue to rely on PlayerPrefs?