public static void SaveAccountMainData(ToolBagTestAccountMainData mainData) { if (mainData == null) { return; } string dataStr = ""; if (mainData.accountDataList != null) { for (int i = 0; i < mainData.accountDataList.Count; i++) { dataStr += JsonUtility.ToJson(mainData.accountDataList[i]); if (i != mainData.accountDataList.Count - 1) { dataStr += "|"; } } } ToolBagTestAccountSaveData saveData = new ToolBagTestAccountSaveData(mainData.accountName, dataStr); PlayerPrefs.SetString(CTestAccountMainKey, JsonUtility.ToJson(saveData)); }
public static ToolBagTestAccountMainData LoadAccountMainData() { string str = PlayerPrefs.GetString(CTestAccountMainKey); if (string.IsNullOrEmpty(str)) { return(new ToolBagTestAccountMainData("TestAccount")); } ToolBagTestAccountSaveData saveData = JsonUtility.FromJson <ToolBagTestAccountSaveData>(str); ToolBagTestAccountMainData mainData = new ToolBagTestAccountMainData(saveData.accountName); string[] dataStrList = saveData.accountDataStr.Split(new char[] { '|' }); for (int i = 0; i < dataStrList.Length; i++) { ToolBagTestAccountData data = JsonUtility.FromJson <ToolBagTestAccountData>(dataStrList[i]); if (data != null) { mainData.accountDataList.Add(data); } } return(mainData); }