ShopManager.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Xml;
  5. public class ShopManager
  6. {
  7. public Dictionary<int, ShopData> dataDict;
  8. public Dictionary<string, ShopData> codeDict;
  9. private ShopData vipData;
  10. private List<ShopData> coinList;
  11. public ShopManager()
  12. {
  13. dataDict = new Dictionary<int, ShopData>();
  14. codeDict = new Dictionary<string, ShopData> ();
  15. coinList = new List<ShopData>();
  16. InitByXML("XML/Config/"+Language.GetCurrentLanguage()+"/shop_config");
  17. }
  18. public void InitByXML(string path)
  19. {
  20. TextAsset textAsset = (TextAsset)Resources.Load(path);
  21. XmlDocument xml = new XmlDocument();
  22. xml.LoadXml(textAsset.text);
  23. XmlNode mapNode = xml.SelectSingleNode("data");
  24. XmlNodeList nodeList = mapNode.SelectNodes("item");
  25. for(int i=0; i<nodeList.Count; i++)
  26. {
  27. ShopData data = new ShopData(nodeList[i]);
  28. if(!dataDict.ContainsKey(data.id))
  29. {
  30. dataDict.Add(data.id, data);
  31. if (data.sort == ShopItem.Sort.VIP.GetHashCode ())
  32. vipData = data;
  33. else if (data.sort == ShopItem.Sort.Crystal.GetHashCode ())
  34. coinList.Add (data);
  35. if (!codeDict.ContainsKey (data.code))
  36. codeDict.Add (data.code, data);
  37. }
  38. else
  39. {
  40. Debuger.LogError("shop " + data.id + " has duplicate");
  41. }
  42. }
  43. }
  44. private static ShopManager instance;
  45. public static ShopManager GetInstance()
  46. {
  47. if(instance == null)
  48. {
  49. instance = new ShopManager();
  50. }
  51. return instance;
  52. }
  53. public ShopData GetVIPData()
  54. {
  55. return vipData;
  56. }
  57. public List<ShopData> GetCoinDataList()
  58. {
  59. return coinList;
  60. }
  61. public ShopData GetDataByCode(string code)
  62. {
  63. ShopData data = null;
  64. codeDict.TryGetValue (code, out data);
  65. return data;
  66. }
  67. public void Pay(string code)
  68. {
  69. ShopData shopData = GetDataByCode(code);
  70. if(shopData != null)
  71. {
  72. // Umeng.GA.Pay((double)shopData.price, Umeng.GA.PaySource.AppStore, shopData.code, 1, (double)shopData.price);
  73. }
  74. }
  75. }