Files
back_cantanBuilding/Assets/Scripts/UI/Home/HomeBtnSelectionPack.cs
2026-05-26 16:15:54 +08:00

39 lines
1.3 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UniRx;
using System;
using GameCore;
using asap.core;
public class HomeBtnSelectionPack : MonoBehaviour
{
private TMP_Text _textTime;
private SelectionPackData _selectionPackData;
private Button _btn;
private void Awake()
{
_textTime = transform.Find("text_time").GetComponent<TMP_Text>();
_btn = GetComponent<Button>();
_selectionPackData = GContext.container.Resolve<SelectionPackData>();
if (!_selectionPackData.IsPackActivated )
gameObject.SetActive( false );
}
// Start is called before the first frame update
private void Start()
{
_btn.onClick.AddListener(async () => { await UIManager.Instance.ShowUI(UITypes.GiftSelectionPanel); });
}
private void OnEnable()
{
_textTime.text = ConvertTools.ConvertTime2(_selectionPackData.RemainingTime);
Observable.Interval(TimeSpan.FromSeconds(1.0f))
.Subscribe(_ => {
_textTime.text = ConvertTools.ConvertTime2(_selectionPackData.RemainingTime);
if (_selectionPackData.RemainingTime.TotalSeconds <= 0
|| _selectionPackData.PurchaseCount >= _selectionPackData.MaxPurchaseCount)
gameObject.SetActive(false); })
.AddTo(this);
}
}