备份CatanBuilding瘦身独立工程
This commit is contained in:
89
Assets/Scripts/UI/Home/HomeBtnEventPack.cs
Normal file
89
Assets/Scripts/UI/Home/HomeBtnEventPack.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class HomeBtnEventPack : MonoBehaviour
|
||||
{
|
||||
private EventPackData _epd;
|
||||
private FishingEvent _currentEvent;
|
||||
private Tables _tables;
|
||||
private TMP_Text _timeText;
|
||||
private Button _btn;
|
||||
private EventPackManager _epm;
|
||||
private IDisposable _timer;
|
||||
private TimeSpan RemainingTime
|
||||
{
|
||||
get
|
||||
{
|
||||
return DateTime.Parse((_currentEvent.TimeDefinition as LimitedTime).EndTime)
|
||||
- ZZTimeHelper.UtcNow();
|
||||
}
|
||||
}
|
||||
private void Awake()
|
||||
{
|
||||
_btn = GetComponent<Button>();
|
||||
_timeText = transform.Find("text_time").GetComponent<TMP_Text>();
|
||||
_tables = GContext.container.Resolve<Tables>();
|
||||
_epd = GContext.container.Resolve<EventPackData>();
|
||||
//Debug.Log($"button: {_epd.CurrentEventID}");
|
||||
|
||||
if (_epd.CurrentEventID == 0)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
_currentEvent = _tables.TbFishingEvent.DataMap[_epd.CurrentEventID];
|
||||
var et = DateTime.Parse((_currentEvent.TimeDefinition as LimitedTime).EndTime);
|
||||
var st = DateTime.Parse((_currentEvent.TimeDefinition as LimitedTime).StartTime);
|
||||
if (ZZTimeHelper.UtcNow() < st || ZZTimeHelper.UtcNow() >= et)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
//Debug.Log("<color=red>get epd</color>");
|
||||
//_epd.UpdateData();
|
||||
if (_epd == null || _epd.CurrentEventID == 0)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
if (GContext.container.Resolve<IUserService>().CreateTotalSeconds()
|
||||
< int.Parse(_currentEvent.ConditionList[0].Param[0]) * 3600
|
||||
|| GContext.container.Resolve<PlayerData>().lv
|
||||
< int.Parse(_currentEvent.ConditionList[1].Param[0]))
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
_epm = _tables.TbEventPackManager.DataMap[_currentEvent.RedirectID];
|
||||
gameObject.SetActive(RemainingTime.TotalSeconds > 0);
|
||||
//Debug.Log(_epd.PurchaseCount);
|
||||
if (RemainingTime.TotalSeconds <= 0 || _epd.PurchaseCount >= _epm.MaxCount)
|
||||
gameObject.SetActive(false);
|
||||
_btn.onClick.AddListener(() => _ = UIManager.Instance.ShowUI(UITypes.GiftPopupPanel_9));
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
_timeText.text = ConvertTools.ConvertTime2(TimeSpan.FromSeconds(RemainingTime.TotalSeconds));
|
||||
_timer = Observable.Interval(TimeSpan.FromSeconds(1.0))
|
||||
.Subscribe(_ =>
|
||||
{
|
||||
_timeText.text = ConvertTools.ConvertTime2(RemainingTime);
|
||||
if (RemainingTime.TotalSeconds <= 0 || _epd.PurchaseCount >= _epm.MaxCount)
|
||||
gameObject.SetActive(false);
|
||||
});
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
_timer?.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user