using System.Collections.Generic; using TMPro; using UnityEngine; using System; using UnityEngine.UI; using UniRx; using asap.core; using game; using GameCore; public class EventLuckyCardButton : EventButtonResource { [SerializeField] private TMP_Text textTimer; [SerializeField] private Button button; [SerializeField] private Image icon; private ILoadResourceService _loadResourceService; EventLuckyGameModel model; IDisposable disposable; private void Awake() { _loadResourceService = GContext.container.Resolve(); } private void OnEnable() { model = GContext.container.Resolve(); if (model == null || !model.IsActive) { gameObject.SetActive(false); if (model != null) { model.Dispose(); } GContext.container.Unregister(); return; } var fishingEvent = model.fishingEvent; UpdateTimer(); disposable = Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer); CheckResource(new List(){ model.eventInfo.MainPrefab, model.eventInfo.ActName , model.eventInfo.IconName}); } private void Start() { button.onClick.AddListener(EnterActAsync); } private void UpdateTimer(long _ = 0L) { textTimer.text = ConvertTools.ConvertTime2(model.RemainingTime); if (!model.IsActive) gameObject.SetActive(false); } private async void EnterActAsync() { try { bool isReady = await _loadResourceService.Loads( new List(){ model.eventInfo.MainPrefab, model.eventInfo.ActName }); if (isReady) { GContext.Publish(new UnloadActToNextAct { actId = model.eventInfo.ActName }); } else { var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel); panel.GetComponent() .SetBtn(true, () => GContext.Publish(new UnloadActToNextAct(model.eventInfo.ActName))); } } catch (Exception e) { Debug.Log($"[EventLuckyCardButton] EnterActError: {e.Message}\n{e.StackTrace}"); throw; } } private void OnDisable() { disposable?.Dispose(); disposable = null; } protected override void OnLoadEventResource() { if (model.IsActive) { GContext.container.Resolve().SetImageSprite(icon, model.eventInfo.IconName); gameObject.SetActive(true); } } }