123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Xml;
- public class ShopManager
- {
- public Dictionary<int, ShopData> dataDict;
- public Dictionary<string, ShopData> codeDict;
- private ShopData vipData;
- private List<ShopData> coinList;
- private List<ShopData> cubeList;
- private List<ShopData> list;
-
- public ShopManager()
- {
- dataDict = new Dictionary<int, ShopData>();
- codeDict = new Dictionary<string, ShopData> ();
- coinList = new List<ShopData>();
- cubeList = new List<ShopData> ();
- list = new List<ShopData> ();
- InitByXML("XML/Config/All/shop_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++)
- {
- ShopData data = new ShopData(nodeList[i]);
- if(!dataDict.ContainsKey(data.id))
- {
- dataDict.Add(data.id, data);
- if (data.sort == BuyUtil.ItemType.VIP.GetHashCode ())
- vipData = data;
- else if (data.sort == BuyUtil.ItemType.Coin.GetHashCode ())
- coinList.Add (data);
- else if (data.sort == BuyUtil.ItemType.Diam.GetHashCode ())
- cubeList.Add (data);
- if (!codeDict.ContainsKey (data.name)) {
- codeDict.Add (data.name, data);
- list.Add (data);
- }
- }
- else
- {
- Debuger.LogError("shop " + data.id + " has duplicate");
- }
- }
- }
- private static ShopManager instance;
- public static ShopManager GetInstance()
- {
- if(instance == null)
- {
- instance = new ShopManager();
- }
- return instance;
- }
- public ShopData GetVIPData()
- {
- return vipData;
- }
- public List<ShopData> GetCoinDataList()
- {
- return coinList;
- }
- public List<ShopData> GetCubeDataList()
- {
- return cubeList;
- }
- public List<ShopData> GetDataList()
- {
- return list;
- }
- public ShopData GetDataByCode(string code)
- {
- ShopData data = null;
- codeDict.TryGetValue (code, out data);
- return data;
- }
-
- }
|