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

81 lines
2.4 KiB
C#

using asap.core;
using cfg;
using GameCore;
using System;
using System.Collections.Generic;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
public class HomeBtnOneTwoPack : MonoBehaviour, IUIRedPoint
{
public const string redKey = "Home.OneTwo";
Image redpoint;
Button btn_enter;
TMP_Text text_time;
FishingEventData fishingEventData;
int packCount;
private void Awake()
{
fishingEventData = GContext.container.Resolve<FishingEventData>();
btn_enter = GetComponent<Button>();
redpoint = transform.Find("redpoint").GetComponent<Image>();
text_time = transform.Find("text_time").GetComponent<TMP_Text>();
Pack1A2Data Pack1A2Data = fishingEventData.Pack1A2Data;
if (Pack1A2Data == null)
{
gameObject.SetActive(false);
return;
}
EventPackManager eventPackManager = fishingEventData.Get1A2EventPackManager();
List<int> packIDs = eventPackManager.VIPPackList[Pack1A2Data.vipLevel];
packCount = packIDs.Count;
if (packCount <= Pack1A2Data.index)
{
gameObject.SetActive(false);
return;
}
}
void OnEnable()
{
SetEndTime();
RedPointManager.Instance.AddRedPoint(redKey, this);
redpoint.enabled = RedPointManager.Instance.GetRedPointState(redKey);
}
private void Start()
{
btn_enter.onClick.AddListener(async () => await UIManager.Instance.GetUIAsync(UITypes.GiftPopupPanel_11));
}
public void SetRedPointState(bool state)
{
redpoint.enabled = state;
}
private void OnDisable()
{
RedPointManager.Instance.RemoveRedPoint(redKey);
}
void SetEndTime()
{
DateTime endTime = fishingEventData.GetEvent1A2EndTime();
TimeSpan now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset();
double seconds = now.TotalSeconds;
if (seconds < 1)
{
gameObject.SetActive(false);
}
else
{
this.AttachTimer((float)seconds,
() => { gameObject.SetActive(false); },
(elapsed) =>
{
now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset();
text_time.text = ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds);
}, useRealTime: true);
}
}
}