123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519 |
- 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<XmlAttributeCollection> GetSkillConfig()
- {
- TextAsset textAsset;
- XmlDocument xmlDoc = new XmlDocument();
- List<XmlNodeList> xmlNodeLists = new List<XmlNodeList>();
- List<XmlAttributeCollection> attributesList = new List<XmlAttributeCollection>();
- 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<XmlAttributeCollection> GetSignConfig()
- {
- TextAsset textAsset;
- XmlNodeList xmlNodeList;
- XmlDocument xmlDoc = new XmlDocument();
- List<XmlAttributeCollection> attributeList = new List<XmlAttributeCollection>();
- 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<XmlAttributeCollection> GetFlowerConfig()
- {
- TextAsset textAsset;
- XmlNodeList xmlNodeList;
- XmlDocument xmlDoc = new XmlDocument();
- List<XmlAttributeCollection> attributesList = new List<XmlAttributeCollection>();
- 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;
- }
- }
|