using System; using System.Collections.Generic; using asap.core; using game; using GameCore; using TMPro; using UniRx; using UnityEngine; using UnityEngine.UI; public class ShootingRangeEntranceButton : EventButtonResource { [SerializeField] private TMP_Text textTimer; [SerializeField] private Button btn; [SerializeField] private Image icon; private EventShootingRangeData _data; private ILoadResourceService _loadResourceService; private const string ShootingRangeResourceLabel = "EventShooting"; private void Awake() { _data = GContext.container.Resolve(); _loadResourceService = GContext.container.Resolve(); if (_data is not { IsActive: true }) { gameObject.SetActive(false); return; } textTimer.text = ConvertTools.ConvertTime2(_data.RemainingTime); Observable.Interval(TimeSpan.FromSeconds(1.0f)).Subscribe(_ => { textTimer.text = ConvertTools.ConvertTime2(_data.RemainingTime); if (_data.RemainingTime.TotalSeconds <= 0) gameObject.SetActive(false); }).AddTo(this); btn.onClick.AddListener(OnEnterShootingRangeAct); RedPointManager.Instance.SetRedPointState(EventShootingRangeData.EntranceRedPointId, _data.DoNeedEntranceRedPoint || _data.DoNeedPackRedPoint); CheckResource(new List() { _data.ShootingRangeAct, _data.EntranceIcon }); } private void OnEnterShootingRangeAct() { try { OnEnterShootingRangeActAsync(); } catch (Exception e) { Debug.Log(e.Message); throw; } } private async void OnEnterShootingRangeActAsync() { //TODO: Will have different bundles in the future. bool isReady = await _loadResourceService.Load(_data.ShootingRangeAct); if (isReady) { Debug.Log($"[Shooting Range] Download Ready!"); GContext.Publish(new UnloadActToNextAct { actId = _data.ShootingRangeAct, TransitionPanel = UITypes.ShootingRangeTransitionPanel }); } else { Debug.Log($"[Shooting Range] Download Not Ready!"); var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel); panel.GetComponent().SetBtn(true, () => GContext.Publish(new UnloadActToNextAct(_data.ShootingRangeAct))); } } protected override void OnLoadEventResource() { if (_data != null && _data.RemainingTime.TotalSeconds > 0) { _ = GContext.container.Resolve().SetImageSprite(icon, _data.EntranceIcon); gameObject.SetActive(true); } } }