using UnityEngine; using TMPro; using UnityEngine.UI; using asap.core; using GameCore; using UniRx; using System; using System.Collections.Generic; public class EventOfferJourneyEntranceBtn : EventButtonResource { [SerializeField] private TMP_Text textTimer; [SerializeField] private Button button; [SerializeField] private Image icon; private ILoadResourceService _loadResourceService; private EventOfferJourneyEntranceData _data; private void Awake() { // CheckForLevelTriggerPack(); var model = GContext.container.Resolve(); if (model == null) { gameObject.SetActive(false); return; } _data = model.ToEntranceData(); if (!_data.IsActive) { gameObject.SetActive(false); return; } UpdateTimer(); Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(this); _loadResourceService = GContext.container.Resolve(); button.onClick.AddListener(OpenPanel); RedPointManager.Instance.SetRedPointState(model.RedPointKey, _data.DoNeedRedPoint); CheckResource(new List() { UITypes.EventOfferJourneyPanel.Path, _data.IconUrl }); GContext.OnEvent().Subscribe(_ => { gameObject.SetActive(false); }).AddTo(this); } 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 OpenPanel() { try { bool isReady = await _loadResourceService.Loads( new List() { UITypes.EventOfferJourneyPanel.Path }); if (isReady) { await UIManager.Instance.ShowUINotLoading(UITypes.EventOfferJourneyPanel); } else { //TODO: Maybe some minor loading UI? } } catch (Exception e) { Debug.Log($"[EventOfferJourney] OpenPanelError: {e.Message}\n{e.StackTrace}"); throw; } } protected override void OnLoadEventResource() { if (_data.IsActive) { GContext.container.Resolve().SetImageSprite(icon, _data.IconUrl); gameObject.SetActive(true); } } private void CheckForLevelTriggerPack() { var ctx = new EventOfferJourneyLvlTriggerTableContext(); if (!ctx.IsEventActive) return; var pfData = EventOfferJourneyLvlTriggerPlayfabData.Load(); if (pfData != null && pfData.RoundCount >= ctx.MaxRoundCount) return; GContext.container.Register().AsSingleton(); var model = GContext.container.Resolve(); if (!model.LoadDataFromPlayfab()) { (model as EventOfferJourneyLvlTriggerData).Init(); } var uiData = model.GetUiData(); UITypes.EventOfferJourneyPanel.SetType(uiData.PanelUrl); UITypes.EventPartnerInfoPopupPanel.SetType(uiData.InfoPanelUrl); } }