Data.cs 18 KB

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