using UnityEngine; using UnityEngine.UI; using TMPro; using asap.core; using UniRx; using System; using System.Collections.Generic; using game; using GameCore; public class EventCanEntranceBtn : EventButtonResource { [SerializeField] private Image icon; [SerializeField] private TMP_Text textTimer; [SerializeField] private Button button; private ILoadResourceService _loadResourceService; private EventCanEntranceBtnData _btnData; private const string EntranceRedPointKey = "eventcan.enter"; private void Awake() { if (GContext.container.Resolve() == null) { gameObject.SetActive(false); return; } var chainPackData = GContext.container.Resolve(); _btnData = GContext.container.Resolve().GetEntranceBtnData(); if (_btnData == null || !_btnData.IsActive) { gameObject.SetActive(false); return; } UpdateTimer(); Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(this); RedPointManager.Instance.SetRedPointState(EntranceRedPointKey, GContext.container.Resolve().TicketCount >= _btnData.RedPointTicketThreshold || chainPackData.DoNeedPackRedPoint); CheckResource(new List() { UITypes.EventCanPanel.Path, EventCanAct.ActAddressable, _btnData.BtnIconUrl }); } private void Start() { button.onClick.AddListener(EnterActAsync); _loadResourceService = GContext.container.Resolve(); } private async void EnterActAsync() { try { bool isReady = await _loadResourceService.Loads( new List() { UITypes.EventCanPanel.Path, EventCanAct.ActAddressable }); if (isReady) { // Debug.Log($"[EventCan] Download Ready!"); GContext.Publish(new UnloadActToNextAct { actId = EventCanAct.ActAddressable, TransitionPanel = UITypes.CloudTransitionPanel }); } else { // Debug.Log($"[EventCan] Download Not Ready!"); var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel); panel.GetComponent() .SetBtn(true, () => GContext.Publish(new UnloadActToNextAct(EventCanAct.ActAddressable))); } } catch (Exception e) { Debug.Log($"[EventCan] EnterActError: {e.Message}\n{e.StackTrace}"); throw; } } private void UpdateTimer(long _ = 0L) { textTimer.text = ConvertTools.ConvertTime2(_btnData.RemainingTime); if (!_btnData.IsActive) Destroy(gameObject); } protected override void OnLoadEventResource() { if (_btnData.IsActive) { GContext.container.Resolve().SetImageSprite(icon, _btnData.BtnIconUrl); gameObject.SetActive(true); } } }