ShopItem.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. public class ShopItem : MonoBehaviour
  6. {
  7. public enum PayType
  8. {
  9. Money = 0,
  10. Coin = 1,
  11. }
  12. private static System.Array payTypeArr = System.Enum.GetValues(typeof(PayType));
  13. public static PayType GetPayTypeByCode(int code)
  14. {
  15. return (PayType)payTypeArr.GetValue(code);
  16. }
  17. public enum Sort
  18. {
  19. None = 0,
  20. VIP = 1,
  21. Crystal = 2,
  22. Cube = 3
  23. }
  24. private static System.Array sortArr = System.Enum.GetValues(typeof(Sort));
  25. public static Sort GetSortByCode(int code)
  26. {
  27. return (Sort)sortArr.GetValue (code);
  28. }
  29. public enum Platform
  30. {
  31. All = 0,
  32. Android = 1,
  33. IOS = 2,
  34. }
  35. private static System.Array platformArr = System.Enum.GetValues(typeof(Platform));
  36. public static Platform GetPlatformByCode(int code)
  37. {
  38. return (Platform)platformArr.GetValue(code);
  39. }
  40. public Text nameTxt;
  41. public Text descTxt;
  42. public Text priceTxt;
  43. public Image icon;
  44. public ShopPanel shopPanel;
  45. private ShopData data;
  46. private PayType type;
  47. private Platform platform;
  48. void OnEnable()
  49. {
  50. Refresh();
  51. }
  52. public void SetData(ShopData data)
  53. {
  54. this.data = data;
  55. if(data == null)
  56. return;
  57. type = GetPayTypeByCode(data.type);
  58. nameTxt.text = GetName();
  59. descTxt.text = GetDescription();
  60. priceTxt.text = Language.GetStr("Shop", "RMB")+GetPrice()+".00";
  61. string path = "Textures/ShopIcon/"+GetIcon();
  62. Sprite sprite = Resources.Load<Sprite>(path);
  63. icon.sprite = sprite;
  64. platform = GetPlatformByCode(data.platform);
  65. // if(Application.platform == RuntimePlatform.Android)
  66. // {
  67. // if(!ExistPlatform(Platform.Android))
  68. // gameObject.SetActive(false);
  69. // }
  70. // else if(Application.platform == RuntimePlatform.IPhonePlayer)
  71. // {
  72. // if(!ExistPlatform(Platform.IOS))
  73. // gameObject.SetActive(false);
  74. // }
  75. UserData userData = Session.GetInstance().myUserData;
  76. if(userData.IsVIP())
  77. {
  78. if(data.code.Contains("VIP"))
  79. {
  80. gameObject.SetActive(false);
  81. }
  82. }
  83. }
  84. public void Refresh()
  85. {
  86. SetData(data);
  87. }
  88. public int GetId()
  89. {
  90. return data.id;
  91. }
  92. public string GetName()
  93. {
  94. return data.name;
  95. }
  96. public string GetDescription()
  97. {
  98. return data.description;
  99. }
  100. public string GetCode()
  101. {
  102. return data.code;
  103. }
  104. public string GetPrice()
  105. {
  106. return data.price;
  107. }
  108. public PayType GetPayType()
  109. {
  110. return type;
  111. }
  112. public string GetIcon()
  113. {
  114. if(StringUtil.Empty(data.icon))
  115. return data.code;
  116. return data.icon;
  117. }
  118. }