using UnityEngine; using System; using System.IO; using System.Xml; using System.Text; using System.Collections; using System.Collections.Generic; public class Data { #region public static XmlNode PlayerNode { get { if (_PlayerNode == null) { _PlayerNode = PlayerDoc.SelectSingleNode("PlayerConfig"); } return _PlayerNode; } set { _PlayerNode = value; } } public static XmlDocument PlayerDoc { get { if (_PlayerDoc == null) { FileInfo fileInfo = new FileInfo(Application.persistentDataPath + "/PlayerConfig.xml"); if (fileInfo.Exists) { StreamReader sr = new StreamReader(Application.persistentDataPath + "/PlayerConfig.xml"); _PlayerDoc = new XmlDocument(); _PlayerDoc.LoadXml(sr.ReadToEnd()); sr.Close(); } else { TextAsset textAsset = (TextAsset)Resources.Load(@"XML\Config\PlayerConfig"); _PlayerDoc = new XmlDocument(); _PlayerDoc.LoadXml(textAsset.text); StreamWriter sw = new StreamWriter(Application.persistentDataPath + "/PlayerConfig.xml"); sw.Write(_PlayerDoc.OuterXml); sw.Close(); } } return _PlayerDoc; } set { _PlayerDoc = value; } } private static XmlNode _PlayerNode; private static XmlDocument _PlayerDoc; #endregion private static void SaveSkillList() { XmlNode xmlNode; XmlAttribute xmlAttribute; xmlNode = PlayerNode.SelectSingleNode("SkillList"); xmlNode.RemoveAll(); for (int i = 0; i < ManaData.SkillList.Count; i++) { if (ManaData.SkillList[i].SkillType == SkillType.Skill) { #region Skill Skill skill = (Skill)ManaData.SkillList[i]; xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, skill.Name, "")); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType")); xmlAttribute.Value = skill.SkillType.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus")); xmlAttribute.Value = skill.ItemStatus.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level")); xmlAttribute.Value = skill.Level.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer")); xmlAttribute.Value = skill.CoolTimer.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer")); xmlAttribute.Value = skill.UseTimer.ToString(); xmlNode = PlayerNode.SelectSingleNode("SkillList"); #endregion } else if (ManaData.SkillList[i].SkillType == SkillType.Pack) { #region Pack Pack pack = (Pack)ManaData.SkillList[i]; xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "礼包", "")); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType")); xmlAttribute.Value = pack.SkillType.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Name")); xmlAttribute.Value = pack.Name; xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus")); xmlAttribute.Value = pack.ItemStatus.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level")); xmlAttribute.Value = pack.Level.ToString(); xmlNode = PlayerNode.SelectSingleNode("SkillList"); #endregion } else if (ManaData.SkillList[i].SkillType == SkillType.Ability) { #region Ability Ability ability = (Ability)ManaData.SkillList[i]; xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, ability.Name, "")); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType")); xmlAttribute.Value = ability.SkillType.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus")); xmlAttribute.Value = ability.ItemStatus.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level")); xmlAttribute.Value = ability.Level.ToString(); xmlNode = PlayerNode.SelectSingleNode("SkillList"); #endregion } else if (ManaData.SkillList[i].SkillType == SkillType.BigSkill) { #region BigSkill BigSkill bigSkill = (BigSkill)ManaData.SkillList[i]; xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, bigSkill.Name, "")); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType")); xmlAttribute.Value = bigSkill.SkillType.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus")); xmlAttribute.Value = bigSkill.ItemStatus.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("BarStatus")); xmlAttribute.Value = bigSkill.BarStatus.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level")); xmlAttribute.Value = bigSkill.Level.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer")); xmlAttribute.Value = bigSkill.CoolTimer.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer")); xmlAttribute.Value = bigSkill.UseTimer.ToString(); xmlNode = PlayerNode.SelectSingleNode("SkillList"); #endregion } } } private static void SavePlantList() { XmlAttributeCollection attributes = PlayerNode.SelectSingleNode("PlantList").Attributes; attributes.RemoveAll(); for (int i = 0; i < ManaGarden.PlantList.Count; i++) { attributes.Append(PlayerDoc.CreateAttribute(ManaGarden.PlantList[i].name)); attributes[i].Value = ManaGarden.PlantList[i].Flower.FlowerInfo.Id.ToString(); } } private static void SaveCommon() { PlayerNode.SelectSingleNode("Sign").Attributes[0].Value = ManaData.Sign.ToString(); PlayerNode.SelectSingleNode("Coin").Attributes[0].Value = ManaData.Coin.ToString("0"); PlayerNode.SelectSingleNode("Level").Attributes[0].Value = ManaData.Level.ToString(); PlayerNode.SelectSingleNode("Person").Attributes[0].Value = ManaData.Person.ToString(); PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value = ManaData.Diamond.ToString(); PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value = DateTime.Now.ToString(); PlayerNode.SelectSingleNode("CoinPerson").Attributes[0].Value = ManaData.CoinPerson.ToString(); PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value = ManaData.CircleTimer.ToString(); } private static void SaveFlowerList() { XmlAttributeCollection attributes = PlayerNode.SelectSingleNode("FlowerList").Attributes; attributes[0].RemoveAll(); XmlAttribute xmlAttribute = attributes.Append(PlayerDoc.CreateAttribute("ID")); for (int i = 0; i < ManaGarden.FlowerInfoList.Count; i++) { if (ManaGarden.FlowerInfoList[i].Unlock) { xmlAttribute.Value += ManaGarden.FlowerInfoList[i].Id - 1; if (i != ManaGarden.FlowerInfoList.Count - 1) { xmlAttribute.Value += " "; } } } } public static void SavePlayerConfig() { SaveSkillList(); SavePlantList(); SaveCommon(); SaveFlowerList(); StreamWriter sw = new StreamWriter(Application.persistentDataPath + "/PlayerConfig.xml"); sw.Write(PlayerDoc.OuterXml); sw.Close(); } private static void ResetSkillList() { XmlNode xmlNode; XmlAttribute xmlAttribute; xmlNode = PlayerNode.SelectSingleNode("SkillList"); xmlNode.RemoveAll(); for (int i = 0; i < ManaData.SkillList.Count; i++) { if (ManaData.SkillList[i].SkillType == SkillType.Skill) { #region Skill Skill skill = (Skill)ManaData.SkillList[i]; xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, skill.Name, "")); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType")); xmlAttribute.Value = skill.SkillType.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus")); xmlAttribute.Value = SkillStatus.Lock.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level")); xmlAttribute.Value = 0.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer")); xmlAttribute.Value = 0.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer")); xmlAttribute.Value = 0.ToString(); xmlNode = PlayerNode.SelectSingleNode("SkillList"); #endregion } else if (ManaData.SkillList[i].SkillType == SkillType.Pack) { #region Pack Pack pack = (Pack)ManaData.SkillList[i]; xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "礼包", "")); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType")); xmlAttribute.Value = pack.SkillType.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Name")); xmlAttribute.Value = pack.Name; xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus")); xmlAttribute.Value = SkillStatus.Lock.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level")); xmlAttribute.Value = 0.ToString(); xmlNode = PlayerNode.SelectSingleNode("SkillList"); #endregion } else if (ManaData.SkillList[i].SkillType == SkillType.Ability) { #region Ability Ability ability = (Ability)ManaData.SkillList[i]; xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, ability.Name, "")); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType")); xmlAttribute.Value = ability.SkillType.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus")); xmlAttribute.Value = SkillStatus.Lock.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level")); xmlAttribute.Value = 0.ToString(); xmlNode = PlayerNode.SelectSingleNode("SkillList"); #endregion } else if (ManaData.SkillList[i].SkillType == SkillType.BigSkill) { #region BigSkill BigSkill bigSkill = (BigSkill)ManaData.SkillList[i]; xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, bigSkill.Name, "")); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType")); xmlAttribute.Value = bigSkill.SkillType.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus")); xmlAttribute.Value = SkillStatus.Lock.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("BarStatus")); xmlAttribute.Value = SkillStatus.Buy.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level")); xmlAttribute.Value = 0.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer")); xmlAttribute.Value = 0.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer")); xmlAttribute.Value = 0.ToString(); xmlNode = PlayerNode.SelectSingleNode("SkillList"); #endregion } } } private static void ResetPlantList() { XmlNode xmlNode = PlayerNode.SelectSingleNode("PlantList"); xmlNode.RemoveAll(); XmlAttribute xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SlotA1")); xmlAttribute.Value = 0.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SlotA2")); xmlAttribute.Value = 1.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SlotA3")); xmlAttribute.Value = 2.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SlotA4")); xmlAttribute.Value = 3.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SlotA5")); xmlAttribute.Value = 4.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SlotA6")); xmlAttribute.Value = 5.ToString(); xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SlotA7")); xmlAttribute.Value = 6.ToString(); } private static void ResetCommon() { PlayerNode.SelectSingleNode("Sign").Attributes[0].Value = "0"; PlayerNode.SelectSingleNode("Coin").Attributes[0].Value = "0"; PlayerNode.SelectSingleNode("Level").Attributes[0].Value = "0"; PlayerNode.SelectSingleNode("Person").Attributes[0].Value = "0"; PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value = "0"; PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value = DateTime.Now.ToString(); PlayerNode.SelectSingleNode("CoinPerson").Attributes[0].Value = "0"; PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value = "0"; } private static void ResetFlowerList() { XmlAttributeCollection attributes = PlayerNode.SelectSingleNode("FlowerList").Attributes; attributes[0].RemoveAll(); XmlAttribute xmlAttribute = attributes.Append(PlayerDoc.CreateAttribute("ID")); xmlAttribute.Value = "0 1 2 3 4 5 6 7 8 9"; } public static void ResetPlayerConfig() { ResetSkillList(); ResetPlantList(); ResetCommon(); ResetFlowerList(); StreamWriter sw = new StreamWriter(Application.persistentDataPath + "/PlayerConfig.xml"); sw.Write(PlayerDoc.OuterXml); sw.Close(); } public static XmlAttributeCollection GetAwardConfig() { TextAsset textAsset; XmlDocument xmlDoc = new XmlDocument(); textAsset = (TextAsset)Resources.Load(@"XML\Config\award_config"); xmlDoc.LoadXml(textAsset.text); XmlNode xmlNode = xmlDoc.SelectSingleNode("data").SelectSingleNode("item"); return xmlNode.Attributes; } public static List GetSkillConfig() { TextAsset textAsset; XmlDocument xmlDoc = new XmlDocument(); List xmlNodeLists = new List(); List attributesList = new List(); textAsset = (TextAsset)Resources.Load(@"XML\Config\pack_config"); xmlDoc.LoadXml(textAsset.text); xmlNodeLists.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item")); textAsset = (TextAsset)Resources.Load(@"XML\Config\skill_config"); xmlDoc.LoadXml(textAsset.text); xmlNodeLists.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item")); textAsset = (TextAsset)Resources.Load(@"XML\Config\ability_config"); xmlDoc.LoadXml(textAsset.text); xmlNodeLists.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item")); for (int i = 0; i < xmlNodeLists.Count; i++) { for (int j = 0; j < xmlNodeLists[i].Count; j++) { attributesList.Add(xmlNodeLists[i][j].Attributes); } } return attributesList; } public static List GetSignConfig() { TextAsset textAsset; XmlNodeList xmlNodeList; XmlDocument xmlDoc = new XmlDocument(); List attributeList = new List(); textAsset = (TextAsset)Resources.Load(@"XML\Config\signin_config"); xmlDoc.LoadXml(textAsset.text); xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item"); for (int i = 0; i < xmlNodeList.Count; i++) { attributeList.Add(xmlNodeList[i].Attributes); } return attributeList; } public static List GetFlowerConfig() { TextAsset textAsset; XmlNodeList xmlNodeList; XmlDocument xmlDoc = new XmlDocument(); List attributesList = new List(); textAsset = (TextAsset) Resources.Load(@"XML\Config\flower_config"); xmlDoc.LoadXml(textAsset.text); xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item"); for (int i = 0; i < xmlNodeList.Count; i++) { attributesList.Add(xmlNodeList[i].Attributes); } return attributesList; } }