My Inventory system, no idea where to move on from where I am. need help in C#.

I have a simple code for a player’s inventory. There is a script that determines the attributes of each item in the game:

using UnityEngine;
using System.Collections;

public class Item {
public string ItemName;
public string ItemDescription;
public int ItemDamage;
public GameObject ItemPrefab;
}

==============================================
The inventory is represented as :

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Inventory : MonoBehaviour {
public List<Item> PlayerInventory = new List<Item>();
public Item ItemInHand = null;
public Rect InvGUIArea = new Rect(0, 0, 0, 0);
void OnGUI () {
GUILayout.BeginArea(InvGUIArea);
GUILayout.BeginVertical();
foreach(Item item in PlayerInventory){
if(item != null){
if(GUILayout.Button(item.ItemName, GUILayout.Width(50), GUILayout.Height(50))){
ItemInHand = item;
}
}
}
GUILayout.EndArea();
GUILayout.EndVertical();
}
}

==================================================
I have not specified this in my previous threads, but I don’t want to just know how to save the inventory to the games online player database, but I want to be able to load it back as well.

The problem is, I don’t know how to do either of those. All I know is how to get the inventory to display the GUI and the item names in it, as well as allow the player to choose what item to hold. Unfortunately I don’t know how to make this whole thing persistent. The system should theoretically work by having an online database that stores each player’s info (username, passcode, gold in his inventory, items in his inventory, the amount of combat experience he has). I only know how to get the client and database to save and load the player’s username, password, experience, and gold. I don’t know how to get it to do the same for the player’s inventory. Note that the player’s amount of gold is NOT considered an actual item in the player’s inventory, but has a slot all for itself that displays the amount of gold the player has. But how am I supposed to make the inventory persistent. Thanks in advance.

Look into serialization, perhaps using a format such as JSON, or else XML. There’s plenty of good tutorials on using that type of serialization technology, which turns your data into a string, and then saving that string somewhere for persistence.

The PlayerPrefs class in Unity provides some very handy persistence stuff and that may be the only mechanism you need. But if you have larger pieces of data, storing it in actual files may be a better route.

When you need it back into memory for use, you would do the opposite: deserialize the string into C# variables.

When the data is serialized, will it matter that one of the item’s attributes is that it has a prefab in it? Or will that get serialized as well. I also do not know how to serialize things to a string.

Could you show me how I could serialize the players inventory to something like:

public string InventoryData = null;

===============================

not to mention I do not know how to take the string and deserialize it back to the player’s inventory.
I need to save it as a string so that the database can easily manage it.