1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using UnityEngine;
- using System.Collections;
- public class WeaponUpgradeHUD : MonoBehaviour
- {
- public float posYWhenWithoutLimitedAmmo;
- UILabel _label;
- float _originalPosY;
- #region Unity Callbacks
- void Awake()
- {
- _label = GetComponent<UILabel>();
- _originalPosY = transform.localPosition.y;
- }
- void OnEnable()
- {
- NotificationCenter.AddListener(OnUpdateWeaponUpgradeAmmoLeft, NotificationType.UpdateWeaponUpgradeAmmoLeft);
- NotificationCenter.AddListener(OnUpdateWeaponUpgradeTimeLeft, NotificationType.UpdateWeaponUpgradeTimeLeft);
- NotificationCenter.AddListener(OnWeaponReset, NotificationType.WeaponReset);
- //Fix position according to mode
- float posY;
- if (LevelsManager.Instance.CurrentLevel.IsWithLimittedAmmo())
- {
- posY = _originalPosY;
- } else
- {
- posY = posYWhenWithoutLimitedAmmo;
- }
- Vector3 pos = transform.localPosition;
- pos.y = posY;
- transform.localPosition = pos;
- }
- void OnDisable()
- {
- NotificationCenter.RemoveListener(OnUpdateWeaponUpgradeAmmoLeft, NotificationType.UpdateWeaponUpgradeAmmoLeft);
- NotificationCenter.RemoveListener(OnUpdateWeaponUpgradeTimeLeft, NotificationType.UpdateWeaponUpgradeTimeLeft);
- NotificationCenter.RemoveListener(OnWeaponReset, NotificationType.WeaponReset);
- }
- #endregion
- #region Notification Callbacks
- void OnUpdateWeaponUpgradeAmmoLeft(Notification note)
- {
- int ammoLeft = (int)note.data;
- _label.text = string.Format(Localization.instance.Get("ammoLeft.label"), ammoLeft);
- }
- void OnUpdateWeaponUpgradeTimeLeft(Notification note)
- {
- int timeLeft = (int)note.data;
- _label.text = string.Format(Localization.instance.Get("weapontime.label"), timeLeft);
- }
- void OnWeaponReset(Notification note)
- {
- _label.text = "";
- }
- #endregion
- }
|