123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Xml;
- public class CraftManager
- {
- private Dictionary<int, CraftConfigData> dataDict;
- private List<CraftConfigData> dataList;
-
- public CraftManager()
- {
- dataDict = new Dictionary<int, CraftConfigData>();
- dataList = new List<CraftConfigData>();
- InitByXML("XML/Config/All/craft_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++)
- {
- CraftConfigData data = new CraftConfigData(nodeList[i]);
- if(!dataDict.ContainsKey(data.id))
- {
- dataDict.Add(data.id, data);
- if(data.id <= 1000)
- dataList.Add(data);
- }
- else
- Debuger.LogError("buff " + data.id + " has duplicate");
- }
- }
-
- private static CraftManager instance;
- public static CraftManager GetInstance()
- {
- if(instance == null)
- {
- instance = new CraftManager();
- }
- return instance;
- }
- public CraftConfigData GetData(int id)
- {
- if(dataDict.ContainsKey(id))
- return dataDict[id];
- Debuger.LogWarning("can not find craft["+id+"]");
- return null;
- }
- public List<CraftConfigData> GetDataList()
- {
- return dataList;
- }
- public int GetRandomCraftId(Player player)
- {
- int index = Random.Range(0, dataList.Count);
- return dataList[index].id;
- }
- }
|