WaveUpsellLabel.cs 1.0 KB

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