using System.Collections.Generic; using TMPro; using UnityEngine; using System; using UnityEngine.UI; using UniRx; using asap.core; using game; using GameCore; public class EventLuckMagicEntranceButton : EventButtonResource { [SerializeField] private TMP_Text textTimer; [SerializeField] private Button button; [SerializeField] private Image icon; private ILoadResourceService _loadResourceService; private EventLuckMagicEntranceData _data; private const string RedPointKey = "eventluckmagic.entrance"; private void Awake() { var model = GContext.container.Resolve(); if (model == null || model.RemainingTime.TotalSeconds <= 0) { gameObject.SetActive(false); return; } _data = model.ToEntranceData(); UpdateTimer(); Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(this); _loadResourceService = GContext.container.Resolve(); button.onClick.AddListener(EnterActAsync); RedPointManager.Instance.SetRedPointState(RedPointKey, model.TicketCount >= EventLuckMagicAct.TableContext.GetTicketRedPointThreshold() || model.ToChainPackData().DoNeedPackRedPoint); CheckResource(new List() { UITypes.EventLuckMagicPanel.Path, _data.Icon, EventLuckMagicAct.ActAddressable }); } private void UpdateTimer(long _ = 0L) { textTimer.text = ConvertTools.ConvertTime2(_data.RemainingTime); if (!_data.IsActive && gameObject.activeSelf) { // Debug.Log("[EventLuckMagic] Time's up in entrance!"); var _model = GContext.container.Resolve(); _model?.DisposeLuckyTaskSubscription(); GContext.container.Unregister(); gameObject.SetActive(false); } } private async void EnterActAsync() { try { bool isReady = await _loadResourceService.Loads( new List() { UITypes.EventLuckMagicPanel.Path, EventLuckMagicAct.ActAddressable }); if (isReady) { GContext.Publish(new UnloadActToNextAct { actId = EventLuckMagicAct.ActAddressable, TransitionPanel = UITypes.CloudTransitionPanel }); } else { var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel); panel.GetComponent() .SetBtn(true, () => GContext.Publish(new UnloadActToNextAct(EventLuckMagicAct.ActAddressable))); } } catch (Exception e) { Debug.Log($"[EventLuckMagic] EnterActError: {e.Message}\n{e.StackTrace}"); throw; } } protected override void OnLoadEventResource() { if (_data.IsActive) { GContext.container.Resolve().SetImageSprite(icon, _data.Icon); gameObject.SetActive(true); } } }