先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
286 lines
10 KiB
C#
286 lines
10 KiB
C#
using asap.core;
|
||
using UI.Home.Event;
|
||
using game;
|
||
using GameCore;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
using UniRx;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
/// <summary>
|
||
/// 触发礼包 ???
|
||
/// </summary>
|
||
public class HomeLeftPanel : MonoBehaviour
|
||
{
|
||
Button but_shop;
|
||
Button btn_gift1;//新手礼包2
|
||
Image image_gift1;
|
||
TMP_Text text_time1;
|
||
Button btn_gift5;//地图礼包
|
||
TMP_Text text_time5;
|
||
Button btn_gift6;//新手礼包1 第一次体力不足
|
||
TMP_Text text_time6;
|
||
Button btn_gift2;//礼包链
|
||
Image image_gift2;
|
||
public HomePanel homePanel;
|
||
TMP_Text text_chainGiftPack;
|
||
Timer chainGiftPackTimer;
|
||
int triggerPackListCount1 = -1;//新手礼包2
|
||
int triggerPackListCount6 = -1;//新手礼包1 第一次体力不足
|
||
int triggerPackListCount53 = -1;//地图礼包
|
||
|
||
int gift1ID;
|
||
int gift6ID;
|
||
int gift53ID;
|
||
public List<TriggerPackBuyData> triggerPackList1;
|
||
public List<TriggerPackBuyData> triggerPackList6;
|
||
public List<TriggerPackBuyData> triggerPackList53;
|
||
protected CompositeDisposable disposables = new CompositeDisposable();
|
||
IDisposable disRequestSvrTime;
|
||
TriggerPackData triggerPackData;
|
||
private void Awake()
|
||
{
|
||
but_shop = transform.Find("btn_shop").GetComponent<Button>();
|
||
btn_gift1 = transform.Find("btn_giftrod").GetComponent<Button>();
|
||
image_gift1 = transform.Find("btn_giftrod/icon").GetComponent<Image>();
|
||
btn_gift2 = transform.Find("btn_giftchain").GetComponent<Button>();
|
||
image_gift2 = transform.Find("btn_giftchain/icon").GetComponent<Image>();
|
||
btn_gift5 = transform.Find("btn_giftmap").GetComponent<Button>();
|
||
btn_gift6 = transform.Find("btn_giftbeginner").GetComponent<Button>();
|
||
text_chainGiftPack = transform.Find("btn_giftchain/text_time").GetComponent<TMP_Text>();
|
||
text_time1 = transform.Find("btn_giftrod/text_time").GetComponent<TMP_Text>();
|
||
text_time5 = transform.Find("btn_giftmap/text_time").GetComponent<TMP_Text>();
|
||
text_time6 = transform.Find("btn_giftbeginner/text_time").GetComponent<TMP_Text>();
|
||
}
|
||
|
||
private void Start()
|
||
{
|
||
GContext.OnEvent<TriggerPackEvent>().Subscribe(TriggerPackEvent).AddTo(disposables);
|
||
|
||
but_shop.onClick.AddListener(() =>
|
||
{
|
||
homePanel.OnPushPanelOrScene(UITypes.FishingShopPanel);
|
||
});
|
||
btn_gift2.onClick.AddListener(() =>
|
||
{
|
||
ShowGiftUI(btn_gift2, UITypes.GiftChainCommon_SubmarinePanel);
|
||
});
|
||
btn_gift1.onClick.AddListener(() =>
|
||
{
|
||
// CommerceNoviceGiftPopupPanel 已禁用
|
||
});
|
||
|
||
//钓鱼券
|
||
btn_gift5.onClick.AddListener(() =>
|
||
{
|
||
ShowGiftUI(btn_gift5, UITypes.MapPackPanel);
|
||
});
|
||
//破冰
|
||
btn_gift6.onClick.AddListener(() =>
|
||
{
|
||
ShowGiftUI(btn_gift6, UITypes.GiftPopupPanel_6);
|
||
});
|
||
//体力不足
|
||
//btn_gift8.onClick.AddListener(() =>
|
||
//{
|
||
// ShowGiftUI(btn_gift8, UITypes.GiftPopupPanel_8);
|
||
//});
|
||
//开始计时
|
||
SetTriggerPackTimer();
|
||
GContext.container.Resolve<PlayerData>().RecoveryEnergy();
|
||
}
|
||
async void ShowGiftUI(Button btn, UIType GiftPopupPanel)
|
||
{
|
||
// 退出自动钓鱼
|
||
//homePanel.ExitAutoFishing();
|
||
btn.enabled = false;
|
||
await UIManager.Instance.ShowUILoad(GiftPopupPanel);
|
||
btn.enabled = true;
|
||
}
|
||
|
||
void SystemSwitch()
|
||
{
|
||
triggerPackData = GContext.container.Resolve<TriggerPackData>();
|
||
gift1ID = 0;
|
||
triggerPackList1 = triggerPackData.GetTriggerPackList(2);
|
||
triggerPackListCount1 = triggerPackList1.Count;
|
||
if (triggerPackListCount1 > 0)
|
||
{
|
||
TriggerPackBuyData _noticeGift = triggerPackList1[0];
|
||
gift1ID = _noticeGift.ID;
|
||
}
|
||
btn_gift1.gameObject.SetActive(triggerPackListCount1 > 0);
|
||
|
||
gift6ID = 0;
|
||
triggerPackList6 = triggerPackData.GetTriggerPackList(1);
|
||
triggerPackListCount6 = triggerPackList6.Count;
|
||
if (triggerPackListCount6 > 0)
|
||
{
|
||
gift6ID = triggerPackList6[0].ID;
|
||
}
|
||
btn_gift6.gameObject.SetActive(triggerPackListCount6 > 0);
|
||
|
||
gift53ID = 0;
|
||
triggerPackList53 = triggerPackData.GetTriggerPackList(53);
|
||
triggerPackListCount53 = triggerPackList53.Count;
|
||
if (triggerPackListCount53 > 0)
|
||
{
|
||
gift53ID = triggerPackList53[triggerPackListCount53 - 1].ID;
|
||
}
|
||
btn_gift5.gameObject.SetActive(triggerPackListCount53 > 0);
|
||
|
||
but_shop.gameObject.SetActive(GContext.container.Resolve<PlayerShopData>().IsShopOpen);
|
||
btn_gift2.gameObject.SetActive(GContext.container.Resolve<PlayerShopData>().IsOpenChainGiftPack());
|
||
SetChainGiftPackTimer();
|
||
}
|
||
void TriggerPackEvent(TriggerPackEvent triggerPackEvent)
|
||
{
|
||
SystemSwitch();
|
||
|
||
CurRewardQCount curRewardQCount = new CurRewardQCount();
|
||
GContext.Publish(curRewardQCount);
|
||
if (curRewardQCount.count <= 0)
|
||
{
|
||
int faceCount = GContext.container.Resolve<IFaceUIService>().GetFaceUICount();
|
||
if (faceCount == 0)
|
||
{
|
||
GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide("HomePanel");
|
||
}
|
||
else
|
||
{
|
||
GContext.container.Resolve<IFaceUIService>().ShowFaceUI();
|
||
}
|
||
}
|
||
}
|
||
|
||
public void SetChainGiftPackTimer()
|
||
{
|
||
if (GContext.container.Resolve<PlayerShopData>().IsOpenChainGiftPack())
|
||
{
|
||
if (chainGiftPackTimer == null)
|
||
{
|
||
DateTime endTime = GContext.container.Resolve<PlayerShopData>().GetChainEndTime();
|
||
TimeSpan now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset();
|
||
double seconds = now.TotalSeconds;
|
||
chainGiftPackTimer = this.AttachTimer((float)seconds, InitChainGiftPack,
|
||
(elapsed) =>
|
||
{
|
||
now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset();
|
||
text_chainGiftPack.text = ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds);
|
||
}, useRealTime: true);
|
||
btn_gift2.gameObject.SetActive(true);
|
||
GContext.container.Resolve<IUIService>().SetImageSprite(image_gift2, GContext.container.Resolve<PlayerShopData>().chainPackM.Icon);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
btn_gift2.gameObject.SetActive(false);
|
||
chainGiftPackTimer?.Cancel();
|
||
chainGiftPackTimer = null;
|
||
}
|
||
}
|
||
void InitChainGiftPack()
|
||
{
|
||
chainGiftPackTimer?.Cancel();
|
||
chainGiftPackTimer = null;
|
||
btn_gift2.gameObject.SetActive(false);
|
||
GContext.container.Resolve<FishingEventData>().GetEventAndInit(3, 10);
|
||
}
|
||
private System.Threading.CancellationTokenSource tokenSource;
|
||
|
||
void OnApplicationPause(bool is_pause)
|
||
{
|
||
if (is_pause)
|
||
{
|
||
tokenSource?.Cancel();
|
||
tokenSource = null;
|
||
GContext.container.Resolve<PlayerData>().StopRecoveryEnergy();
|
||
disRequestSvrTime?.Dispose();
|
||
disRequestSvrTime = GContext.OnEvent<RequestSvrTimeEvent>().Subscribe(RequestSvrTimeEvent);
|
||
}
|
||
}
|
||
void RequestSvrTimeEvent(RequestSvrTimeEvent e)
|
||
{
|
||
if (e.Status)
|
||
{
|
||
disRequestSvrTime?.Dispose();
|
||
disRequestSvrTime = null;
|
||
Debug.Log("RequestSvrTimeEvent AllRefresh");
|
||
GContext.container.Resolve<PlayerShopData>().InitShopPackData();
|
||
GContext.container.Resolve<PlayerData>().RecoveryEnergy();
|
||
SetTriggerPackTimer();
|
||
}
|
||
}
|
||
|
||
public async void SetTriggerPackTimer()
|
||
{
|
||
tokenSource = new System.Threading.CancellationTokenSource();
|
||
SystemSwitch();
|
||
DateTime dateTime = ZZTimeHelper.UtcNow().UtcNowOffset();
|
||
DateTime dateTime1 = dateTime.AddDays(1).Date;
|
||
try
|
||
{
|
||
var token = tokenSource.Token;
|
||
while (!token.IsCancellationRequested && dateTime.Ticks < dateTime1.Ticks)
|
||
{
|
||
UpdateTriggerTimer();
|
||
await System.Threading.Tasks.Task.Delay(1000);
|
||
dateTime = dateTime.AddSeconds(1);
|
||
}
|
||
if (!token.IsCancellationRequested)
|
||
{
|
||
Refresh();
|
||
SetTriggerPackTimer();
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Debug.LogError(e);
|
||
}
|
||
}
|
||
void Refresh()
|
||
{
|
||
GContext.container.Resolve<PlayerShopData>().InitShopPackData();
|
||
GContext.container.Resolve<TriggerPackData>().InitPackData();
|
||
}
|
||
public void UpdateTriggerTimer()
|
||
{
|
||
var list = GContext.container.Resolve<TriggerPackData>().triggerPackList;
|
||
int count = list.Count;
|
||
if (count > 0)
|
||
{
|
||
TriggerPackBuyData stateEvent;
|
||
for (int i = count - 1; i >= 0; i--)
|
||
{
|
||
stateEvent = list[i];
|
||
TimeSpan timeSpan = GContext.container.Resolve<TriggerPackData>().GetCurTriggerPackEndTime(stateEvent);
|
||
if (timeSpan.TotalSeconds <= 0)
|
||
{
|
||
continue;
|
||
}
|
||
if (stateEvent.ID == gift1ID)
|
||
{
|
||
text_time1.text = ConvertTools.ConvertTime2(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
|
||
}
|
||
else if (stateEvent.ID == gift53ID)
|
||
{
|
||
text_time5.text = ConvertTools.ConvertTime2(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
|
||
}
|
||
else if (stateEvent.ID == gift6ID)
|
||
{
|
||
text_time6.text = ConvertTools.ConvertTime2(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
private void OnDestroy()
|
||
{
|
||
disposables?.Dispose();
|
||
disposables = null;
|
||
tokenSource?.Cancel();
|
||
tokenSource = null;
|
||
GContext.container?.Resolve<PlayerData>()?.StopRecoveryEnergy();
|
||
}
|
||
}
|