Data.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. using System;
  2. using UnityEngine;
  3. using System.Xml;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. public class Data
  7. {
  8. #region
  9. public static XmlNode PlayerNode
  10. {
  11. get
  12. {
  13. if (_PlayerNode == null)
  14. {
  15. _PlayerNode = PlayerDoc.SelectSingleNode("PlayerConfig");
  16. }
  17. return _PlayerNode;
  18. }
  19. set { _PlayerNode = value; }
  20. }
  21. public static XmlDocument PlayerDoc
  22. {
  23. get
  24. {
  25. if (_PlayerDoc == null)
  26. {
  27. TextAsset textAsset = (TextAsset)Resources.Load(@"XML\Config\PlayerConfig");
  28. _PlayerDoc = new XmlDocument();
  29. _PlayerDoc.LoadXml(textAsset.text);
  30. }
  31. return _PlayerDoc;
  32. }
  33. set { _PlayerDoc = value; }
  34. }
  35. private static XmlNode _PlayerNode;
  36. private static XmlDocument _PlayerDoc;
  37. #endregion
  38. private static void SaveSkillList()
  39. {
  40. XmlNode xmlNode;
  41. XmlAttribute xmlAttribute;
  42. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  43. xmlNode.RemoveAll();
  44. for (int i = 0; i < ManaData.SkillList.Count; i++)
  45. {
  46. if (ManaData.SkillList[i].SkillType == SkillType.Skill)
  47. {
  48. #region Skill
  49. Skill skill = (Skill)ManaData.SkillList[i];
  50. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, skill.Name, ""));
  51. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  52. xmlAttribute.Value = skill.SkillType.ToString();
  53. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  54. xmlAttribute.Value = skill.ItemStatus.ToString();
  55. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  56. xmlAttribute.Value = skill.Level.ToString();
  57. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer"));
  58. xmlAttribute.Value = skill.CoolTimer.ToString();
  59. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer"));
  60. xmlAttribute.Value = skill.UsingTimer.ToString();
  61. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  62. #endregion
  63. }
  64. else if (ManaData.SkillList[i].SkillType == SkillType.Pack)
  65. {
  66. #region Pack
  67. Pack pack = (Pack)ManaData.SkillList[i];
  68. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "礼包", ""));
  69. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  70. xmlAttribute.Value = pack.SkillType.ToString();
  71. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Name"));
  72. xmlAttribute.Value = pack.Name;
  73. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  74. xmlAttribute.Value = pack.ItemStatus.ToString();
  75. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  76. xmlAttribute.Value = pack.Level.ToString();
  77. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  78. #endregion
  79. }
  80. else if (ManaData.SkillList[i].SkillType == SkillType.Ability)
  81. {
  82. #region Ability
  83. Ability ability = (Ability)ManaData.SkillList[i];
  84. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, ability.Name, ""));
  85. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  86. xmlAttribute.Value = ability.SkillType.ToString();
  87. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  88. xmlAttribute.Value = ability.ItemStatus.ToString();
  89. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  90. xmlAttribute.Value = ability.Level.ToString();
  91. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  92. #endregion
  93. }
  94. else if (ManaData.SkillList[i].SkillType == SkillType.BigSkill)
  95. {
  96. #region BigSkill
  97. BigSkill bigSkill = (BigSkill)ManaData.SkillList[i];
  98. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, bigSkill.Name, ""));
  99. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  100. xmlAttribute.Value = bigSkill.SkillType.ToString();
  101. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  102. xmlAttribute.Value = bigSkill.ItemStatus.ToString();
  103. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("BarStatus"));
  104. xmlAttribute.Value = bigSkill.BarStatus.ToString();
  105. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  106. xmlAttribute.Value = bigSkill.Level.ToString();
  107. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer"));
  108. xmlAttribute.Value = bigSkill.CoolTimer.ToString();
  109. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer"));
  110. xmlAttribute.Value = bigSkill.UsingTimer.ToString();
  111. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  112. #endregion
  113. }
  114. }
  115. PlayerDoc.Save(Application.dataPath + @"\Resources\XML\Config\PlayerConfig.xml");
  116. }
  117. private static void SavePlantList()
  118. {
  119. XmlAttributeCollection attributes = PlayerNode.SelectSingleNode("PlantList").Attributes;
  120. attributes.RemoveAll();
  121. for (int i = 0; i < ManaGarden.PlantList.Count; i++)
  122. {
  123. attributes.Append(PlayerDoc.CreateAttribute(ManaGarden.PlantList[i].PosTra.name));
  124. attributes[i].Value = ManaGarden.PlantList[i].Id.ToString();
  125. }
  126. PlayerDoc.Save(Application.dataPath + @"\Resources\XML\Config\PlayerConfig.xml");
  127. }
  128. private static void SaveCommon()
  129. {
  130. PlayerNode.SelectSingleNode("Coin").Attributes[0].Value = ManaData.Coin.ToString("0");
  131. PlayerNode.SelectSingleNode("Level").Attributes[0].Value = ManaData.Level.ToString();
  132. PlayerNode.SelectSingleNode("Person").Attributes[0].Value = ManaData.Person.ToString();
  133. PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value = ManaData.Diamond.ToString();
  134. PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value = DateTime.Now.ToString();
  135. PlayerNode.SelectSingleNode("CoinPerson").Attributes[0].Value = ManaData.CoinPerson.ToString();
  136. PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value = ManaData.CircleTimer.ToString();
  137. PlayerDoc.Save(Application.dataPath + @"\Resources\XML\Config\PlayerConfig.xml");
  138. }
  139. private static void SaveFlowerList()
  140. {
  141. XmlAttributeCollection attributes = PlayerNode.SelectSingleNode("FlowerList").Attributes;
  142. attributes[0].RemoveAll();
  143. XmlAttribute xmlAttribute = attributes.Append(PlayerDoc.CreateAttribute("ID"));
  144. foreach (var kv in ManaGarden.FlowerDic)
  145. {
  146. if (kv.Value.Unlock)
  147. {
  148. xmlAttribute.Value += kv.Key + " ";
  149. }
  150. }
  151. xmlAttribute.Value.Trim(' ');
  152. PlayerDoc.Save(Application.dataPath + @"\Resources\XML\Config\PlayerConfig.xml");
  153. }
  154. public static void SavePlayerConfig()
  155. {
  156. SaveSkillList();
  157. SavePlantList();
  158. SaveCommon();
  159. SaveFlowerList();
  160. }
  161. private static void ResetSkillList()
  162. {
  163. XmlNode xmlNode;
  164. XmlAttribute xmlAttribute;
  165. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  166. xmlNode.RemoveAll();
  167. for (int i = 0; i < ManaData.SkillList.Count; i++)
  168. {
  169. if (ManaData.SkillList[i].SkillType == SkillType.Skill)
  170. {
  171. #region Skill
  172. Skill skill = (Skill)ManaData.SkillList[i];
  173. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, skill.Name, ""));
  174. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  175. xmlAttribute.Value = skill.SkillType.ToString();
  176. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  177. xmlAttribute.Value = SkillStatus.Lock.ToString();
  178. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  179. xmlAttribute.Value = 0.ToString();
  180. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer"));
  181. xmlAttribute.Value = 0.ToString();
  182. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer"));
  183. xmlAttribute.Value = 0.ToString();
  184. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  185. #endregion
  186. }
  187. else if (ManaData.SkillList[i].SkillType == SkillType.Pack)
  188. {
  189. #region Pack
  190. Pack pack = (Pack)ManaData.SkillList[i];
  191. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, "礼包", ""));
  192. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  193. xmlAttribute.Value = pack.SkillType.ToString();
  194. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Name"));
  195. xmlAttribute.Value = pack.Name;
  196. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  197. xmlAttribute.Value = SkillStatus.Lock.ToString();
  198. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  199. xmlAttribute.Value = 0.ToString();
  200. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  201. #endregion
  202. }
  203. else if (ManaData.SkillList[i].SkillType == SkillType.Ability)
  204. {
  205. #region Ability
  206. Ability ability = (Ability)ManaData.SkillList[i];
  207. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, ability.Name, ""));
  208. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  209. xmlAttribute.Value = ability.SkillType.ToString();
  210. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  211. xmlAttribute.Value = SkillStatus.Lock.ToString();
  212. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  213. xmlAttribute.Value = 0.ToString();
  214. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  215. #endregion
  216. }
  217. else if (ManaData.SkillList[i].SkillType == SkillType.BigSkill)
  218. {
  219. #region BigSkill
  220. BigSkill bigSkill = (BigSkill)ManaData.SkillList[i];
  221. xmlNode = xmlNode.AppendChild(PlayerDoc.CreateNode(XmlNodeType.Element, bigSkill.Name, ""));
  222. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("SkillType"));
  223. xmlAttribute.Value = bigSkill.SkillType.ToString();
  224. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("ItemStatus"));
  225. xmlAttribute.Value = SkillStatus.Lock.ToString();
  226. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("BarStatus"));
  227. xmlAttribute.Value = SkillStatus.Buy.ToString();
  228. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("Level"));
  229. xmlAttribute.Value = 0.ToString();
  230. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("CdTimer"));
  231. xmlAttribute.Value = 0.ToString();
  232. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("EffectTimer"));
  233. xmlAttribute.Value = 0.ToString();
  234. xmlNode = PlayerNode.SelectSingleNode("SkillList");
  235. #endregion
  236. }
  237. }
  238. PlayerDoc.Save(Application.dataPath + @"\Resources\XML\Config\PlayerConfig.xml");
  239. }
  240. private static void ResetPlantList()
  241. {
  242. XmlNode xmlNode = PlayerNode.SelectSingleNode("PlantList");
  243. xmlNode.RemoveAll();
  244. XmlAttribute xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("FlowerTraA1"));
  245. xmlAttribute.Value = 1.ToString();
  246. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("FlowerTraA2"));
  247. xmlAttribute.Value = 2.ToString();
  248. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("FlowerTraA3"));
  249. xmlAttribute.Value = 3.ToString();
  250. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("FlowerTraA4"));
  251. xmlAttribute.Value = 4.ToString();
  252. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("FlowerTraA5"));
  253. xmlAttribute.Value = 5.ToString();
  254. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("FlowerTraA6"));
  255. xmlAttribute.Value = 6.ToString();
  256. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("FlowerTraA7"));
  257. xmlAttribute.Value = 7.ToString();
  258. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("FlowerTraA8"));
  259. xmlAttribute.Value = 8.ToString();
  260. xmlAttribute = xmlNode.Attributes.Append(PlayerDoc.CreateAttribute("FlowerTraA9"));
  261. xmlAttribute.Value = 9.ToString();
  262. PlayerDoc.Save(Application.dataPath + @"\Resources\XML\Config\PlayerConfig.xml");
  263. }
  264. private static void ResetCommon()
  265. {
  266. PlayerNode.SelectSingleNode("Coin").Attributes[0].Value = "0";
  267. PlayerNode.SelectSingleNode("Level").Attributes[0].Value = "0";
  268. PlayerNode.SelectSingleNode("Person").Attributes[0].Value = "1";
  269. PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value = "0";
  270. PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value = DateTime.Now.ToString();
  271. PlayerNode.SelectSingleNode("CoinPerson").Attributes[0].Value = "1";
  272. PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value = "0";
  273. PlayerDoc.Save(Application.dataPath + @"\Resources\XML\Config\PlayerConfig.xml");
  274. }
  275. private static void ResetFlowerList()
  276. {
  277. XmlAttributeCollection attributes = PlayerNode.SelectSingleNode("FlowerList").Attributes;
  278. attributes[0].RemoveAll();
  279. XmlAttribute xmlAttribute = attributes.Append(PlayerDoc.CreateAttribute("ID"));
  280. xmlAttribute.Value = "1 2 3 4 5 6 7 8 9";
  281. PlayerDoc.Save(Application.dataPath + @"\Resources\XML\Config\PlayerConfig.xml");
  282. }
  283. public static void ResetPlayerConfig()
  284. {
  285. ResetSkillList();
  286. ResetPlantList();
  287. ResetCommon();
  288. ResetFlowerList();
  289. PlayerDoc.Save(Application.dataPath + @"\Resources\XML\Config\PlayerConfig.xml");
  290. }
  291. public static List<XmlAttributeCollection> GetSkillConfig()
  292. {
  293. TextAsset textAsset;
  294. XmlDocument xmlDoc = new XmlDocument();
  295. List<XmlNodeList> xmlNodeLists = new List<XmlNodeList>();
  296. List<XmlAttributeCollection> attributesList = new List<XmlAttributeCollection>();
  297. textAsset = (TextAsset)Resources.Load(@"XML\Config\pack_config");
  298. xmlDoc.LoadXml(textAsset.text);
  299. xmlNodeLists.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  300. textAsset = (TextAsset)Resources.Load(@"XML\Config\skill_config");
  301. xmlDoc.LoadXml(textAsset.text);
  302. xmlNodeLists.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  303. textAsset = (TextAsset)Resources.Load(@"XML\Config\ability_config");
  304. xmlDoc.LoadXml(textAsset.text);
  305. xmlNodeLists.Add(xmlDoc.SelectSingleNode("data").SelectNodes("item"));
  306. for (int i = 0; i < xmlNodeLists.Count; i++)
  307. {
  308. for (int j = 0; j < xmlNodeLists[i].Count; j++)
  309. {
  310. attributesList.Add(xmlNodeLists[i][j].Attributes);
  311. }
  312. }
  313. return attributesList;
  314. }
  315. public static List<XmlAttributeCollection> GetFlowerConfig()
  316. {
  317. XmlNodeList xmlNodeList;
  318. XmlDocument xmlDoc = new XmlDocument();
  319. List<XmlAttributeCollection> attributesList = new List<XmlAttributeCollection>();
  320. TextAsset textAsset = (TextAsset) Resources.Load(@"XML\Config\flower_config");
  321. xmlDoc.LoadXml(textAsset.text);
  322. xmlNodeList = xmlDoc.SelectSingleNode("data").SelectNodes("item");
  323. for (int i = 0; i < xmlNodeList.Count; i++)
  324. {
  325. attributesList.Add(xmlNodeList[i].Attributes);
  326. }
  327. return attributesList;
  328. }
  329. }