85 lines
3.0 KiB
C#
85 lines
3.0 KiB
C#
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using System;
|
|
using UnityEngine.UI;
|
|
using UniRx;
|
|
using asap.core;
|
|
using game;
|
|
using GameCore;
|
|
|
|
public class EventLuckMagicEntranceButton : EventButtonResource
|
|
{
|
|
[SerializeField] private TMP_Text textTimer;
|
|
[SerializeField] private Button button;
|
|
[SerializeField] private Image icon;
|
|
private ILoadResourceService _loadResourceService;
|
|
private EventLuckMagicEntranceData _data;
|
|
private const string RedPointKey = "eventluckmagic.entrance";
|
|
|
|
private void Awake()
|
|
{
|
|
var model = GContext.container.Resolve<EventLuckMagicModel>();
|
|
if (model == null || model.RemainingTime.TotalSeconds <= 0)
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
_data = model.ToEntranceData();
|
|
UpdateTimer();
|
|
Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(this);
|
|
_loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
button.onClick.AddListener(EnterActAsync);
|
|
RedPointManager.Instance.SetRedPointState(RedPointKey,
|
|
model.TicketCount >= EventLuckMagicAct.TableContext.GetTicketRedPointThreshold()
|
|
|| model.ToChainPackData().DoNeedPackRedPoint);
|
|
CheckResource(new List<string>() { UITypes.EventLuckMagicPanel.Path, _data.Icon, EventLuckMagicAct.ActAddressable });
|
|
}
|
|
|
|
private void UpdateTimer(long _ = 0L)
|
|
{
|
|
textTimer.text = ConvertTools.ConvertTime2(_data.RemainingTime);
|
|
if (!_data.IsActive && gameObject.activeSelf)
|
|
{
|
|
// Debug.Log("[EventLuckMagic] Time's up in entrance!");
|
|
var _model = GContext.container.Resolve<EventLuckMagicModel>();
|
|
_model?.DisposeLuckyTaskSubscription();
|
|
GContext.container.Unregister<EventLuckMagicModel>();
|
|
gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
private async void EnterActAsync()
|
|
{
|
|
try
|
|
{
|
|
bool isReady = await _loadResourceService.Loads(
|
|
new List<string>() { UITypes.EventLuckMagicPanel.Path, EventLuckMagicAct.ActAddressable });
|
|
if (isReady)
|
|
{
|
|
GContext.Publish(new UnloadActToNextAct { actId = EventLuckMagicAct.ActAddressable, TransitionPanel = UITypes.CloudTransitionPanel });
|
|
}
|
|
else
|
|
{
|
|
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
panel.GetComponent<CloudTransitionPanel>()
|
|
.SetBtn(true, () => GContext.Publish(new UnloadActToNextAct(EventLuckMagicAct.ActAddressable)));
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.Log($"<color=#22a6f2>[EventLuckMagic] EnterActError: {e.Message}\n{e.StackTrace}</color>");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
protected override void OnLoadEventResource()
|
|
{
|
|
if (_data.IsActive)
|
|
{
|
|
GContext.container.Resolve<IUIService>().SetImageSprite(icon, _data.Icon);
|
|
gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|