1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- 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;
-
- public ShopManager()
- {
- dataDict = new Dictionary<int, ShopData>();
- codeDict = new Dictionary<string, ShopData> ();
- coinList = new List<ShopData>();
- InitByXML("XML/Config/"+Language.GetCurrentLanguage()+"/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 == ShopItem.Sort.VIP.GetHashCode ())
- vipData = data;
- else if (data.sort == ShopItem.Sort.Crystal.GetHashCode ())
- coinList.Add (data);
- if (!codeDict.ContainsKey (data.code))
- codeDict.Add (data.code, 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 ShopData GetDataByCode(string code)
- {
- ShopData data = null;
- codeDict.TryGetValue (code, out data);
- return data;
- }
- public void Pay(string code)
- {
- ShopData shopData = GetDataByCode(code);
- if(shopData != null)
- {
- // Umeng.GA.Pay((double)shopData.price, Umeng.GA.PaySource.AppStore, shopData.code, 1, (double)shopData.price);
- }
- }
-
- }
|