12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Xml;
- public class PowerDataManager
- {
- public Dictionary<int, PowerData> dataDict;
-
- public PowerDataManager()
- {
- dataDict = new Dictionary<int, PowerData>();
- InitByXML("XML/Config/All/power_config");
- }
-
- public void InitByXML(string path)
- {
- TextAsset textAsset = (TextAsset)Resources.Load(path);
-
- XmlDocument xml = new XmlDocument();
- xml.LoadXml(textAsset.text);
-
- XmlNode mapNode = xml.SelectSingleNode("data");
-
- XmlNodeList nodeList = mapNode.SelectNodes("item");
- for(int i=0; i<nodeList.Count; i++)
- {
- PowerData data = new PowerData(nodeList[i]);
- if(!dataDict.ContainsKey(data.id))
- dataDict.Add(data.id, data);
- else
- Debuger.LogError("power " + data.id + " has duplicate");
- }
- }
-
- private static PowerDataManager instance;
- public static PowerDataManager GetInstance()
- {
- if(instance == null)
- {
- instance = new PowerDataManager();
- }
- return instance;
- }
-
- public PowerData GetData(int id)
- {
- if(dataDict.ContainsKey(id))
- return dataDict[id];
- Debuger.LogWarning("can not find buff["+id+"]");
- return null;
- }
-
- public Power CreatePower(int index, int id, IPowerOwner owner, bool isAttack=false)
- {
- Power power = new Power(GetData(id), owner, isAttack);
- power.index = index;
- return power;
- }
- }
|