1存储:遍历整个背包的格子。将有子物体的格子给储存下来
public void SaveInventory()
{
StringBuilder sb = new StringBuilder();
foreach (Slot slot in slotList)
{
if (slot.transform.childCount > 0)
{
ItemUI itemUI = slot.transform.GetChild(0).GetComponent();
sb.Append(itemUI.Item.ID + ","+itemUI.Amount+"-");
}
else
{
sb.Append("0-");
}
}
PlayerPrefs.SetString(this.gameObject.name, sb.ToString());
}
2加载:
public void LoadInventory()
{
if (PlayerPrefs.HasKey(this.gameObject.name) == false) return;
string str = PlayerPrefs.GetString(this.gameObject.name);
//print(str);
string[] itemArray = str.Split('-');
for (int i = 0; i < itemArray.