96 lines
2.8 KiB
C#
96 lines
2.8 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 EventLuckyCardButton : EventButtonResource
|
|
{
|
|
[SerializeField] private TMP_Text textTimer;
|
|
[SerializeField] private Button button;
|
|
[SerializeField] private Image icon;
|
|
private ILoadResourceService _loadResourceService;
|
|
EventLuckyGameModel model;
|
|
IDisposable disposable;
|
|
private void Awake()
|
|
{
|
|
_loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
}
|
|
private void OnEnable()
|
|
{
|
|
model = GContext.container.Resolve<EventLuckyGameModel>();
|
|
if (model == null || !model.IsActive)
|
|
{
|
|
gameObject.SetActive(false);
|
|
if (model != null)
|
|
{
|
|
model.Dispose();
|
|
}
|
|
GContext.container.Unregister<EventLuckyGameModel>();
|
|
return;
|
|
}
|
|
var fishingEvent = model.fishingEvent;
|
|
|
|
UpdateTimer();
|
|
disposable = Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer);
|
|
CheckResource(new List<string>(){
|
|
model.eventInfo.MainPrefab,
|
|
model.eventInfo.ActName ,
|
|
model.eventInfo.IconName});
|
|
}
|
|
private void Start()
|
|
{
|
|
button.onClick.AddListener(EnterActAsync);
|
|
}
|
|
private void UpdateTimer(long _ = 0L)
|
|
{
|
|
textTimer.text = ConvertTools.ConvertTime2(model.RemainingTime);
|
|
if (!model.IsActive)
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
private async void EnterActAsync()
|
|
{
|
|
try
|
|
{
|
|
bool isReady = await _loadResourceService.Loads(
|
|
new List<string>(){
|
|
model.eventInfo.MainPrefab,
|
|
model.eventInfo.ActName });
|
|
if (isReady)
|
|
{
|
|
GContext.Publish(new UnloadActToNextAct { actId = model.eventInfo.ActName });
|
|
}
|
|
else
|
|
{
|
|
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
panel.GetComponent<CloudTransitionPanel>()
|
|
.SetBtn(true, () => GContext.Publish(new UnloadActToNextAct(model.eventInfo.ActName)));
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.Log($"<color=#22a6f2>[EventLuckyCardButton] EnterActError: {e.Message}\n{e.StackTrace}</color>");
|
|
throw;
|
|
}
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
disposable?.Dispose();
|
|
disposable = null;
|
|
}
|
|
|
|
protected override void OnLoadEventResource()
|
|
{
|
|
if (model.IsActive)
|
|
{
|
|
GContext.container.Resolve<IUIService>().SetImageSprite(icon, model.eventInfo.IconName);
|
|
gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|