WaveUpsellLabel.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using UnityEngine;
  2. using System.Collections;
  3. using ICTS.Localization;
  4. using TMPro;
  5. public class WaveUpsellLabel : MonoBehaviour
  6. {
  7. TextMeshProUGUI label;
  8. void Awake()
  9. {
  10. label = GetComponent<TextMeshProUGUI>();
  11. }
  12. #region Unity Callbacks
  13. void OnEnable()
  14. {
  15. UpdateLabel();
  16. CoreNotificationCenter.AddListener(OnPurchase, CoreNotificationType.PurchaseSuccessful);
  17. }
  18. void OnDisable()
  19. {
  20. CoreNotificationCenter.RemoveListener(OnPurchase, CoreNotificationType.PurchaseSuccessful);
  21. }
  22. #endregion
  23. void OnPurchase(CoreNotification note)
  24. {
  25. UpdateLabel();
  26. }
  27. void UpdateLabel()
  28. {
  29. IAPProduct product = StoreManager.Instance.GetProduct(StoreProductId.specialwave_5);
  30. string price;
  31. if (product == null)
  32. {
  33. price = Localization.instance.Get("priceNotAvailable");
  34. } else
  35. {
  36. price = product.currencyCode+" "+product.price;
  37. }
  38. label.text = string.Format(Localization.instance.Get("waveUpsell.text"), GetCountInInventory().ToString(), price);
  39. label.text = label.text.ToUpper();
  40. }
  41. int GetCountInInventory()
  42. {
  43. return InventoryManager.Instance.GetItemCount(InventoryItem.specialwave);
  44. }
  45. }