146 lines
5.0 KiB
C#
146 lines
5.0 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace game
|
|
{
|
|
public class HomeBtnPinball : EventButtonResource
|
|
{
|
|
[SerializeField] private TMP_Text textTimer;
|
|
Button btn;
|
|
|
|
private DateTime endDateTime;
|
|
|
|
// EventPinballDataManager m_DataManager;
|
|
|
|
#region 生命周期
|
|
void Awake()
|
|
{
|
|
btn = GetComponent<Button>();
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
// m_DataManager = GContext.container.Resolve<EventPinballDataManager>();
|
|
// m_DataManager.Init();
|
|
|
|
// 活动倒计时处理
|
|
FishingEventData fishingEventData = GContext.container.Resolve<FishingEventData>();
|
|
int fishingEventID = fishingEventData.GetEvent(4, 6);
|
|
if (fishingEventID < 0)
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
|
|
Tables tables = GContext.container.Resolve<Tables>();
|
|
FishingEvent fishingEvent = tables.TbFishingEvent[fishingEventID];
|
|
endDateTime = DateTime.Parse((fishingEvent.TimeDefinition as LimitedTime)?.EndTime);
|
|
|
|
TimeSpan all = GetRemainingTime(endDateTime);
|
|
double seconds = all.TotalSeconds - 1;
|
|
if (seconds < 1)
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
StartCoroutine(AttachTimer((float)seconds));
|
|
textTimer.text = ConvertTools.ConvertTime2(all);
|
|
|
|
Observable.Interval(TimeSpan.FromSeconds(1.0f)).Subscribe(_ =>
|
|
{
|
|
TimeSpan tmpAll = GetRemainingTime(endDateTime);
|
|
textTimer.text = ConvertTools.ConvertTime2(tmpAll);
|
|
if (tmpAll.TotalSeconds <= 0)
|
|
gameObject.SetActive(false);
|
|
}).AddTo(this);
|
|
|
|
btn.onClick.AddListener(async () =>
|
|
{
|
|
// EventPinballMain eventPinballMain = m_DataManager.ContinueGame();
|
|
|
|
string actName = "FishingPinballAct";
|
|
// List<string> resList = new List<string>();
|
|
// resList.Add(actName);
|
|
//
|
|
// if (eventPinballMain != null)
|
|
// {
|
|
// resList.AddRange(eventPinballMain.Addressable);
|
|
// if (!string.IsNullOrEmpty(eventPinballMain.Bgm))
|
|
// {
|
|
// resList.Add(eventPinballMain.Bgm);
|
|
// }
|
|
// }
|
|
//
|
|
// ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
// bool isCanEnter = await loadResourceService.Loads(resList);
|
|
// if (isCanEnter)
|
|
// {
|
|
// GContext.Publish(new UnloadActToNextAct(actName));
|
|
// }
|
|
// else
|
|
// {
|
|
// var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
// panel.GetComponent<CloudTransitionPanel>().SetBtn(true, () => GContext.Publish(new UnloadActToNextAct(actName)));
|
|
// }
|
|
});
|
|
|
|
// EventPinballMain eventPinballMain = m_DataManager.ContinueGame();
|
|
|
|
// string actName = "FishingPinballAct";
|
|
// List<string> resList = new List<string>
|
|
// {
|
|
// actName,
|
|
// eventPinballMain.Icon
|
|
// };
|
|
//
|
|
// if (eventPinballMain != null)
|
|
// {
|
|
// resList.AddRange(eventPinballMain.Addressable);
|
|
// if (!string.IsNullOrEmpty(eventPinballMain.Bgm))
|
|
// {
|
|
// resList.Add(eventPinballMain.Bgm);
|
|
// }
|
|
// }
|
|
// m_DataManager.SetRedPoint();
|
|
// CheckResource(resList);
|
|
}
|
|
#endregion
|
|
|
|
private TimeSpan GetRemainingTime(DateTime endDateTime)
|
|
{
|
|
return endDateTime - ZZTimeHelper.UtcNow();
|
|
}
|
|
|
|
IEnumerator AttachTimer(float time)
|
|
{
|
|
yield return new WaitForSeconds(time);
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
protected override void OnLoadEventResource()
|
|
{
|
|
// TimeSpan all = GetRemainingTime(endDateTime);
|
|
// double seconds = all.TotalSeconds - 1;
|
|
// if (seconds > 1)
|
|
// {
|
|
// EventPinballMain eventPinballMain = m_DataManager.ContinueGame();
|
|
// if (eventPinballMain != null)
|
|
// {
|
|
// Image btn_icon = transform.Find("icon").GetComponent<Image>();
|
|
// GContext.container.Resolve<IUIService>().SetImageSprite(btn_icon, eventPinballMain.Icon, "HomePanel");
|
|
// }
|
|
// gameObject.SetActive(true);
|
|
// }
|
|
}
|
|
}
|
|
}
|