Data.cs 17 KB

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