using DG.Tweening; using UnityEngine; using UnityEngine.UI; namespace Panels { public class HUDPanel : PanelBase { [SerializeField] private Text currentLevel; [SerializeField] private Text collectedCash; [SerializeField] private Image cashProgress; [SerializeField] private RectTransform cashIcon; [SerializeField] private GameObject removeAdsBtn; [SerializeField] private JoyStickPanel joyStickPanel; [SerializeField] private PopUpPanel popUpPanel; [SerializeField] [TextArea] private string removeAdsFailMsg; [SerializeField] [TextArea] private string removeAdsSuccessMsg; private int _targetObstacles; private bool _isAnimating; private Tween _tween; private void Start() { if (UnityAdController.AreAdsDisabled()) removeAdsBtn.SetActive(false); } public void RemoveAds() { joyStickPanel.ClosePanelImmediately(); IAPController.PurchaseAdRemoval(PurchaseSuccess, PurchaseFailure); return; void PurchaseSuccess() { UnityAdController.DisableAds(); removeAdsBtn.SetActive(false); popUpPanel.OpenPopUp(PopUpType.Information, removeAdsSuccessMsg, joyStickPanel.OpenPanelImmediately); } void PurchaseFailure() => popUpPanel.OpenPopUp(PopUpType.Error, removeAdsFailMsg, joyStickPanel.OpenPanelImmediately); } public void BindData(int targetObstacles, int inLevel) { _targetObstacles = targetObstacles; collectedCash.text = "0$"; currentLevel.text = inLevel < 10 ? $"0{inLevel}" : inLevel.ToString(); } public void UpdateProgress(int collectedObstacles) { collectedCash.text = $"{collectedObstacles * 10}$"; var progress = collectedObstacles / (float) _targetObstacles; _tween?.Kill(); _tween = cashProgress.DOFillAmount(progress, .25f); if (_isAnimating) return; _isAnimating = true; cashIcon.DOShakeScale(.3f) .OnComplete(() => _isAnimating = false); } } }