public UpgradeUserData GetUserData(string name) { if (userDatas.ContainsKey(name)) { return(userDatas[name]); } var userData = userDatas[name] = new UpgradeUserData(); userData.upgradeDataName = name; userData.currentLevel = 0; return(userData); }
public void Save() { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = "\t"; settings.NewLineOnAttributes = true; StringBuilder sb = new StringBuilder(); using (XmlWriter writer = XmlTextWriter.Create(sb, settings)) { XmlSerializer serializer = new XmlSerializer(typeof(UpgradeUserData[])); var array = new UpgradeUserData[userDatas.Count]; userDatas.Values.CopyTo(array, 0); serializer.Serialize(writer, array); } PlayerPrefs.SetString(userDataPath, sb.ToString()); }