131 lines
4.5 KiB
C#
131 lines
4.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using asap.core;
|
|
using GameCore;
|
|
using TMPro;
|
|
using System;
|
|
using cfg;
|
|
using UniRx;
|
|
|
|
namespace game
|
|
{
|
|
public class HomeBtnPotion : EventButtonResource
|
|
{
|
|
[SerializeField] private TMP_Text textTimer;
|
|
Button btn_potion;
|
|
Image icon;
|
|
string iconUrl;
|
|
private DateTime endDateTime;
|
|
|
|
#region 生命周期
|
|
void Awake()
|
|
{
|
|
btn_potion = GetComponent<Button>();
|
|
icon = transform.Find("icon").GetComponent<Image>();
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
EventPotionDataManager eventPotionDataManager = GContext.container.Resolve<EventPotionDataManager>();
|
|
eventPotionDataManager.Init();
|
|
|
|
// 红点处理
|
|
if (eventPotionDataManager != null)
|
|
{
|
|
if (eventPotionDataManager.IsRedDotDisplayed()) RedPointManager.Instance.SetRedPointState(RedPointName.Home_Potion, true);
|
|
else RedPointManager.Instance.SetRedPointState(RedPointName.Home_Potion, false);
|
|
}
|
|
else RedPointManager.Instance.SetRedPointState(RedPointName.Home_Potion, false);
|
|
|
|
// 活动倒计时处理
|
|
FishingEventData fishingEventData = GContext.container.Resolve<FishingEventData>();
|
|
int fishingEventID = fishingEventData.GetEvent(4, 5);
|
|
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);
|
|
EventPotionMain potion = tables.TbEventPotionMain[fishingEvent.RedirectID];
|
|
iconUrl = potion.Icon;
|
|
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_potion.onClick.AddListener(async () =>
|
|
{
|
|
List<string> resList = new List<string>
|
|
{
|
|
"FishingPotionAct",// 公共包
|
|
potion.Prefab// 场景
|
|
};
|
|
|
|
ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
bool isCanEnter = await loadResourceService.Loads(resList);
|
|
if (isCanEnter)
|
|
{
|
|
GContext.Publish(new UnloadActToNextAct("FishingPotionAct"));
|
|
}
|
|
else
|
|
{
|
|
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
panel.GetComponent<CloudTransitionPanel>().SetBtn(true, () => GContext.Publish(new UnloadActToNextAct("FishingPotionAct")));
|
|
}
|
|
});
|
|
List<string> resList = new List<string>
|
|
{
|
|
"FishingPotionAct",// 公共包
|
|
potion.Prefab,// 场景
|
|
iconUrl// icon
|
|
};
|
|
|
|
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)
|
|
{
|
|
GContext.container.Resolve<IUIService>().SetImageSprite(icon, iconUrl);
|
|
gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
}
|