备份CatanBuilding瘦身独立工程
This commit is contained in:
119
Assets/Scripts/UI/Home/HomeBtnWashing.cs
Normal file
119
Assets/Scripts/UI/Home/HomeBtnWashing.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class HomeBtnWashing : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text textTimer;
|
||||
Button btn_washing;
|
||||
|
||||
private DateTime endDateTime;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
btn_washing = GetComponent<Button>();
|
||||
|
||||
EventWashingDataManager eventWashingDataManager = GContext.container.Resolve<EventWashingDataManager>();
|
||||
eventWashingDataManager.Init();
|
||||
eventWashingDataManager.InitGameData();
|
||||
|
||||
// 更换图片
|
||||
var data = eventWashingDataManager.GetCurrentEventWashing();
|
||||
if (data != null)
|
||||
{
|
||||
Image icon = transform.Find("icon").GetComponent<Image>();
|
||||
GContext.container.Resolve<IUIService>().SetImageSprite(icon, data.IconID);
|
||||
}
|
||||
|
||||
// 红点处理
|
||||
if (eventWashingDataManager != null)
|
||||
{
|
||||
if (eventWashingDataManager.IsRedDotDisplayed()) RedPointManager.Instance.SetRedPointState(RedPointName.Home_Washing, true);
|
||||
else RedPointManager.Instance.SetRedPointState(RedPointName.Home_Washing, false);
|
||||
}
|
||||
else RedPointManager.Instance.SetRedPointState(RedPointName.Home_Washing, false);
|
||||
|
||||
// 活动倒计时处理
|
||||
FishingEventData fishingEventData = GContext.container.Resolve<FishingEventData>();
|
||||
int fishingEventID = fishingEventData.GetEvent(4, 4);
|
||||
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);
|
||||
|
||||
//endDateTime = fishingEventData.GetEventEndTime(fishingEventID);
|
||||
//TimeSpan all = endDateTime - ZZTimeHelper.UtcNow();
|
||||
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);
|
||||
}
|
||||
|
||||
private TimeSpan GetRemainingTime(DateTime endDateTime)
|
||||
{
|
||||
return endDateTime - ZZTimeHelper.UtcNow();
|
||||
}
|
||||
|
||||
IEnumerator AttachTimer(float time)
|
||||
{
|
||||
yield return new WaitForSeconds(time);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
btn_washing.onClick.AddListener(async () =>
|
||||
{
|
||||
EventWashingDataManager eventWashingDataManager = GContext.container.Resolve<EventWashingDataManager>();
|
||||
eventWashingDataManager.Init();
|
||||
|
||||
string res = eventWashingDataManager.GetPreLoadStepResName();
|
||||
|
||||
List<string> resList = new List<string>();
|
||||
resList.Add("FishingYachtAct");// 公共包
|
||||
resList.Add("audio_eventwashing_bgm");// 音效包
|
||||
resList.Add("Garage"); // 场景
|
||||
resList.Add(res); // 步骤,游戏
|
||||
|
||||
ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
||||
bool isCanEnter = await loadResourceService.Loads(resList);
|
||||
if (isCanEnter)
|
||||
{
|
||||
GContext.Publish(new UnloadActToNextAct("FishingYachtAct"));
|
||||
}
|
||||
else
|
||||
{
|
||||
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
||||
panel.GetComponent<CloudTransitionPanel>().SetBtn(true, () => GContext.Publish(new UnloadActToNextAct("FishingYachtAct")));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user