90 lines
3.1 KiB
C#
90 lines
3.1 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using asap.core;
|
|
using UniRx;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using game;
|
|
using GameCore;
|
|
|
|
public class EventCanEntranceBtn : EventButtonResource
|
|
{
|
|
[SerializeField] private Image icon;
|
|
[SerializeField] private TMP_Text textTimer;
|
|
[SerializeField] private Button button;
|
|
private ILoadResourceService _loadResourceService;
|
|
private EventCanEntranceBtnData _btnData;
|
|
private const string EntranceRedPointKey = "eventcan.enter";
|
|
|
|
private void Awake()
|
|
{
|
|
if (GContext.container.Resolve<EventCanTableContext>() == null)
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
var chainPackData = GContext.container.Resolve<EventCanChainPackData>();
|
|
_btnData = GContext.container.Resolve<EventCanTableContext>().GetEntranceBtnData();
|
|
if (_btnData == null || !_btnData.IsActive)
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
UpdateTimer();
|
|
Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(this);
|
|
RedPointManager.Instance.SetRedPointState(EntranceRedPointKey,
|
|
GContext.container.Resolve<EventCanModel>().TicketCount >= _btnData.RedPointTicketThreshold
|
|
|| chainPackData.DoNeedPackRedPoint);
|
|
CheckResource(new List<string>() { UITypes.EventCanPanel.Path, EventCanAct.ActAddressable, _btnData.BtnIconUrl });
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
button.onClick.AddListener(EnterActAsync);
|
|
_loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
}
|
|
|
|
private async void EnterActAsync()
|
|
{
|
|
try
|
|
{
|
|
bool isReady = await _loadResourceService.Loads(
|
|
new List<string>() { UITypes.EventCanPanel.Path, EventCanAct.ActAddressable });
|
|
if (isReady)
|
|
{
|
|
// Debug.Log($"<color=#22a6f2>[EventCan] Download Ready!</color>");
|
|
GContext.Publish(new UnloadActToNextAct { actId = EventCanAct.ActAddressable, TransitionPanel = UITypes.CloudTransitionPanel });
|
|
}
|
|
else
|
|
{
|
|
// Debug.Log($"<color=#22a6f2>[EventCan] Download Not Ready!</color>");
|
|
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
panel.GetComponent<CloudTransitionPanel>()
|
|
.SetBtn(true, () => GContext.Publish(new UnloadActToNextAct(EventCanAct.ActAddressable)));
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.Log($"<color=#22a6f2>[EventCan] 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);
|
|
}
|
|
}
|
|
}
|