WeaponUpgradeHUD.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using UnityEngine;
  2. using System.Collections;
  3. public class WeaponUpgradeHUD : MonoBehaviour
  4. {
  5. public float posYWhenWithoutLimitedAmmo;
  6. UILabel _label;
  7. float _originalPosY;
  8. #region Unity Callbacks
  9. void Awake()
  10. {
  11. _label = GetComponent<UILabel>();
  12. _originalPosY = transform.localPosition.y;
  13. }
  14. void OnEnable()
  15. {
  16. NotificationCenter.AddListener(OnUpdateWeaponUpgradeAmmoLeft, NotificationType.UpdateWeaponUpgradeAmmoLeft);
  17. NotificationCenter.AddListener(OnUpdateWeaponUpgradeTimeLeft, NotificationType.UpdateWeaponUpgradeTimeLeft);
  18. NotificationCenter.AddListener(OnWeaponReset, NotificationType.WeaponReset);
  19. //Fix position according to mode
  20. float posY;
  21. if (LevelsManager.Instance.CurrentLevel.IsWithLimittedAmmo())
  22. {
  23. posY = _originalPosY;
  24. } else
  25. {
  26. posY = posYWhenWithoutLimitedAmmo;
  27. }
  28. Vector3 pos = transform.localPosition;
  29. pos.y = posY;
  30. transform.localPosition = pos;
  31. }
  32. void OnDisable()
  33. {
  34. NotificationCenter.RemoveListener(OnUpdateWeaponUpgradeAmmoLeft, NotificationType.UpdateWeaponUpgradeAmmoLeft);
  35. NotificationCenter.RemoveListener(OnUpdateWeaponUpgradeTimeLeft, NotificationType.UpdateWeaponUpgradeTimeLeft);
  36. NotificationCenter.RemoveListener(OnWeaponReset, NotificationType.WeaponReset);
  37. }
  38. #endregion
  39. #region Notification Callbacks
  40. void OnUpdateWeaponUpgradeAmmoLeft(Notification note)
  41. {
  42. int ammoLeft = (int)note.data;
  43. _label.text = string.Format(Localization.instance.Get("ammoLeft.label"), ammoLeft);
  44. }
  45. void OnUpdateWeaponUpgradeTimeLeft(Notification note)
  46. {
  47. int timeLeft = (int)note.data;
  48. _label.text = string.Format(Localization.instance.Get("weapontime.label"), timeLeft);
  49. }
  50. void OnWeaponReset(Notification note)
  51. {
  52. _label.text = "";
  53. }
  54. #endregion
  55. }