PowerDataManager.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Xml;
  5. public class PowerDataManager
  6. {
  7. public Dictionary<int, PowerData> dataDict;
  8. public PowerDataManager()
  9. {
  10. dataDict = new Dictionary<int, PowerData>();
  11. InitByXML("XML/Config/All/power_config");
  12. }
  13. public void InitByXML(string path)
  14. {
  15. TextAsset textAsset = (TextAsset)Resources.Load(path);
  16. XmlDocument xml = new XmlDocument();
  17. xml.LoadXml(textAsset.text);
  18. XmlNode mapNode = xml.SelectSingleNode("data");
  19. XmlNodeList nodeList = mapNode.SelectNodes("item");
  20. for(int i=0; i<nodeList.Count; i++)
  21. {
  22. PowerData data = new PowerData(nodeList[i]);
  23. if(!dataDict.ContainsKey(data.id))
  24. dataDict.Add(data.id, data);
  25. else
  26. Debuger.LogError("power " + data.id + " has duplicate");
  27. }
  28. }
  29. private static PowerDataManager instance;
  30. public static PowerDataManager GetInstance()
  31. {
  32. if(instance == null)
  33. {
  34. instance = new PowerDataManager();
  35. }
  36. return instance;
  37. }
  38. public PowerData GetData(int id)
  39. {
  40. if(dataDict.ContainsKey(id))
  41. return dataDict[id];
  42. Debuger.LogWarning("can not find buff["+id+"]");
  43. return null;
  44. }
  45. public Power CreatePower(int index, int id, IPowerOwner owner, bool isAttack=false)
  46. {
  47. Power power = new Power(GetData(id), owner, isAttack);
  48. power.index = index;
  49. return power;
  50. }
  51. }