99 lines
3.5 KiB
C#
99 lines
3.5 KiB
C#
using asap.core;
|
|
using game;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
using GameCore;
|
|
using UniRx;
|
|
using System.Collections.Generic;
|
|
|
|
public class EventBreakEntranceButton : EventButtonResource
|
|
{
|
|
[SerializeField] private Image icon;
|
|
[SerializeField] private TMP_Text textTimer;
|
|
[SerializeField] private Button button;
|
|
private ILoadResourceService _loadResourceService;
|
|
private EventBreakEntranceData _btnData;
|
|
private const string EntranceRedPointKey = "eventbreak.enter";
|
|
|
|
private void Awake()
|
|
{
|
|
if (EventBreakAct.Ctx == null)
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
_btnData = EventBreakAct.Ctx.GetEntranceButtonData();
|
|
var _drillModel = GContext.container.Resolve<DrillModel>();
|
|
if (_btnData == null || !_btnData.IsActive)
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
UpdateTimer();
|
|
Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(this);
|
|
var chainPackData = GContext.container.Resolve<DrillModel>().ToChainPackData();
|
|
RedPointManager.Instance.SetRedPointState(EntranceRedPointKey,
|
|
_drillModel.TicketCount >= _btnData.RedPointTicketThreshold
|
|
|| chainPackData.DoNeedPackRedPoint);
|
|
CheckResource(new List<string>() { UITypes.EventBreakPanel.Path, EventBreakAct.ActAddressable, _btnData.BtnIconUrl });
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
button.onClick.AddListener(EnterDrillActAsync);
|
|
_loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
}
|
|
|
|
private async void EnterDrillActAsync()
|
|
{
|
|
try
|
|
{
|
|
bool isReady = await _loadResourceService.Loads(
|
|
new List<string>() { UITypes.EventBreakPanel.Path, EventBreakAct.ActAddressable });
|
|
if (isReady)
|
|
{
|
|
// Debug.Log($"<color=#22a6f2>[EventBreak] Download Ready!</color>");
|
|
GContext.Publish(new UnloadActToNextAct { actId = EventBreakAct.ActAddressable, TransitionPanel = UITypes.CloudTransitionPanel });
|
|
}
|
|
else
|
|
{
|
|
// Debug.Log($"<color=#22a6f2>[EventBreak] Download Not Ready!</color>");
|
|
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
panel.GetComponent<CloudTransitionPanel>().SetBtn(true, () => GContext.Publish(new UnloadActToNextAct(EventBreakAct.ActAddressable)));
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.Log($"<color=#22a6f2>[EventBreak] EnterActError: {e.Message}\n{e.StackTrace}</color>");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
private void UpdateTimer(long _ = 0L)
|
|
{
|
|
textTimer.text = ConvertTools.ConvertTime2(_btnData.RemainingTime);
|
|
if (!_btnData.IsActive)
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
protected override void OnLoadEventResource()
|
|
{
|
|
if (_btnData.IsActive)
|
|
{
|
|
GContext.container.Resolve<IUIService>().SetImageSprite(icon, _btnData.BtnIconUrl);
|
|
gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
public class EventBreakEntranceData
|
|
{
|
|
public string BtnIconUrl { get; set; }
|
|
public DateTime ExpiryTime { get; set; }
|
|
public DateTime StartTime { get; set; }
|
|
public TimeSpan RemainingTime => ExpiryTime - ZZTimeHelper.UtcNow();
|
|
public bool IsActive => ZZTimeHelper.UtcNow() >= StartTime && ZZTimeHelper.UtcNow() < ExpiryTime;
|
|
public int RedPointTicketThreshold { get; set; }
|
|
}
|