using asap.core; using cfg; using game; using GameCore; using Script.RuntimeScript; using System; using System.Collections.Generic; using TMPro; using UnityEngine.UI; public class HomeSandigButton : EventButtonResource { public Button btn_sandig; public TMP_Text txt_sandig; public Image icon_sandig; private Timer _sanddingTime; Tables _tables; int activityId; //4-1 private void Awake() { _tables = GContext.container.Resolve(); } private void Start() { btn_sandig.onClick.AddListener(OnClickSandDig); } private void OnEnable() { activityId = GContext.container.Resolve().GetActivityId(); if (activityId <= 0) { btn_sandig.gameObject.SetActive(false); txt_sandig.text = string.Empty; return; } var eventData = _tables.TbFishingEvent.GetOrDefault(activityId); if (eventData != null) { var sandInit = _tables.TbDiggingActivityInit.GetOrDefault(eventData.RedirectID); List strings = new List() { sandInit.Icon }; strings.AddRange(sandInit.DownloadLabel); CheckResource(strings); } else { btn_sandig.gameObject.SetActive(false); } } void OnClickSandDig() { InSandDigAct(); } async void InSandDigAct() { activityId = GContext.container.Resolve().GetActivityId(); if (activityId <= 0) { return; } var eventData = _tables.TbFishingEvent.GetOrDefault(activityId); if (eventData != null) { var sandInit = _tables.TbDiggingActivityInit.GetOrDefault(eventData.RedirectID); ILoadResourceService loadResourceService = GContext.container.Resolve(); bool isCanEnter = await loadResourceService.Loads(sandInit.DownloadLabel); if (isCanEnter) { EnterSandDigAct(); } else { var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel); panel.GetComponent().SetBtn(true, EnterSandDigAct); } } } void EnterSandDigAct() { GContext.Publish(new UnloadActToNextAct("SandDigAct")); } private void ShowSandDigTime() { //显示倒计时 if (_sanddingTime == null) { activityId = GContext.container.Resolve().GetActivityId(); if (activityId <= 0) { btn_sandig.gameObject.SetActive(false); txt_sandig.text = string.Empty; return; } var eventData = _tables.TbFishingEvent.GetOrDefault(activityId); if (eventData != null) { var sandInit = _tables.TbDiggingActivityInit.GetOrDefault(eventData.RedirectID); GContext.container.Resolve().SetImageSprite(icon_sandig, sandInit.Icon); } btn_sandig.gameObject.SetActive(true); DateTime endTime = GContext.container.Resolve().GetEventEndTime(activityId); TimeSpan now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset(); double seconds = now.TotalSeconds; _sanddingTime = this.AttachTimer((float)seconds, RefreshSandDig, (elapsed) => { now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset(); txt_sandig.text = ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds); }, useRealTime: true); } } private void RefreshSandDig() { _sanddingTime?.Cancel(); _sanddingTime = null; btn_sandig.gameObject.SetActive(false); } private void OnDisable() { _sanddingTime?.Cancel(); _sanddingTime = null; } protected override void OnLoadEventResource() { ShowSandDigTime(); } }