using System; using asap.core; using cfg; using GameCore; using TMPro; using UniRx; using UnityEngine; using UnityEngine.UI; public class BlackFridayCouponBanner : MonoBehaviour { private BlackFridayCouponData _data; [SerializeField] private TMP_Text textBanner, textTimer; [SerializeField] private DiamondShopSlot[] slots; [SerializeField] private Image bgBanner; private readonly IEventAggregator _eventAggregator = new EventAggregator(); public void Awake() { _data = GContext.container.Resolve().CouponData; if (_data is not { IsActive: true }) { SetupBlackFriday(false, _eventAggregator); return; } SetupBlackFriday(true, _eventAggregator); textBanner.text = LocalizationMgr.GetFormatTextValue("UI_GiftPopupPanel_13_5", _data.Multiplier + "%"); textTimer.text = ConvertTools.ConvertTime2(_data.RemainingTime); ColorUtility.TryParseHtmlString( GContext.container.Resolve().TbEventCoupon[_data.RedirectId].FontColorTime, out var c); textTimer.color = c; Observable.Interval(TimeSpan.FromSeconds(1.0f)) .Subscribe(_ => { textTimer.text = ConvertTools.ConvertTime2(_data.RemainingTime); if (!_data.IsActive) SetupBlackFriday(false, _eventAggregator); }).AddTo(this); _eventAggregator.GetEvent().Subscribe(_ => { // _data.SetStateBought(); SetupBlackFriday(_data.IsActive, _eventAggregator); }).AddTo(this); GContext.container.Resolve().SetImageSprite(bgBanner, GContext.container.Resolve().TbEventCoupon[_data.RedirectId].LabelShop1); } private void SetupBlackFriday(bool isOpen, IEventAggregator ea) { if (isOpen) { gameObject.SetActive(true); foreach (var slot in slots) slot.SetUpBlackFriday(true, ea); } else { foreach (var slot in slots) slot.SetUpBlackFriday(false, ea); Destroy(gameObject); } } public class EventTerminateBlackFriday { } }