备份CatanBuilding瘦身独立工程
This commit is contained in:
207
Assets/Scripts/UI/Home/HomeBtnAquarium.cs
Normal file
207
Assets/Scripts/UI/Home/HomeBtnAquarium.cs
Normal file
@@ -0,0 +1,207 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class HomeBtnAquarium : MonoBehaviour
|
||||
{
|
||||
GameObject btn_guild_gray;
|
||||
Button btn_fishingBox;
|
||||
GameObject redpoint;
|
||||
public CanvasGroup homeCanvasGroup;
|
||||
FishingEventData fishingEventData;
|
||||
AquariumManagerData data;
|
||||
List<AquariumSlotData> slotDatas;
|
||||
List<AquariumResultData> aquariumResultDatas;
|
||||
|
||||
bool isred;
|
||||
DateTime refreshTime;
|
||||
private void Awake()
|
||||
{
|
||||
fishingEventData = GContext.container.Resolve<FishingEventData>();
|
||||
btn_guild_gray = transform.Find("icon_gray").gameObject;
|
||||
redpoint = transform.Find("redpoint").gameObject;
|
||||
btn_fishingBox = GetComponent<Button>();
|
||||
bool IsAquariumOpen = fishingEventData.IsAquariumOpen;
|
||||
btn_guild_gray.SetActive(!IsAquariumOpen);
|
||||
if (IsAquariumOpen)
|
||||
{
|
||||
Synchrodata();
|
||||
}
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
btn_fishingBox.onClick.AddListener(OnClickGoTo);
|
||||
//btn_fishingBox.onClick.AddListener(OnClickGoTo);
|
||||
}
|
||||
public void Synchrodata()
|
||||
{
|
||||
//测试
|
||||
//PlayFabMgr.Instance.UpdateUserDataValue(AquariumManager.AquariumEventDataKey, "");
|
||||
|
||||
//从服务器拿数据
|
||||
string dataStr = PlayFabMgr.Instance.GetLocalData(AquariumManager.AquariumEventDataKey);
|
||||
if (string.IsNullOrEmpty(dataStr))
|
||||
{
|
||||
ShowRed();
|
||||
}
|
||||
else
|
||||
{
|
||||
data = Newtonsoft.Json.JsonConvert.DeserializeObject<AquariumManagerData>(dataStr);
|
||||
var nowTime = ZZTimeHelper.UtcNow().UtcNowOffset();
|
||||
refreshTime = nowTime.Date.AddDays(1);
|
||||
if (nowTime.Date.DayOfYear != data.refreshDay)
|
||||
{
|
||||
data.adCount = 0;
|
||||
data.refreshCount = 0;
|
||||
data.refreshDay = nowTime.Date.DayOfYear;
|
||||
}
|
||||
|
||||
if (data.isHome || data.slotDatas == null)
|
||||
{
|
||||
IsHome(nowTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
slotDatas = new List<AquariumSlotData>();
|
||||
int count = data.slot - data.aquariumHurtDatas.Count;
|
||||
if (count > 0)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
AquariumHurtData aquariumHurtData = new AquariumHurtData();
|
||||
data.aquariumHurtDatas.Add(aquariumHurtData);
|
||||
}
|
||||
}
|
||||
count = data.slot - data.aquariumResultDatas.Count;
|
||||
if (count > 0)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
AquariumResultData aquariumResultData = new AquariumResultData();
|
||||
data.aquariumResultDatas.Add(aquariumResultData);
|
||||
}
|
||||
}
|
||||
aquariumResultDatas = data.aquariumResultDatas;
|
||||
|
||||
for (int i = 0; i < data.slot; i++)
|
||||
{
|
||||
var slotData = data.slotDatas[i];
|
||||
if (!slotData.IsResult() && !aquariumResultDatas[slotData.index].IsResult())
|
||||
{
|
||||
slotDatas.Add(slotData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void IsHome(DateTime dateTime)
|
||||
{
|
||||
bool isRefresh = refreshTime < dateTime;
|
||||
if (data.refreshCount < GContext.container.Resolve<Tables>().TbAquariumConfig.RefreshTime || isRefresh)
|
||||
{
|
||||
ShowRed();
|
||||
}
|
||||
}
|
||||
void ShowRed()
|
||||
{
|
||||
isred = true;
|
||||
redpoint.SetActive(true);
|
||||
}
|
||||
async void FishingBox()
|
||||
{
|
||||
if (GContext.container.Resolve<FishingBoxDataProvier>().IsUnclocked)
|
||||
{
|
||||
GameObject go = await UIManager.Instance.ShowUILoad(UITypes.FishingBoxPanel);
|
||||
if (go != null)
|
||||
{
|
||||
GContext.Publish(new HideHomePanelEvent());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var dataProvider = GContext.container.Resolve<FishingBoxDataProvier>();
|
||||
ToastPanel.Show(fishingEventData.GetTipforUnlocked(dataProvider.EventTipID));
|
||||
}
|
||||
}
|
||||
void OnClickGoTo()
|
||||
{
|
||||
if (!fishingEventData.IsAquariumOpen)
|
||||
{
|
||||
ToastPanel.Show(fishingEventData.GetTipforUnlocked(fishingEventData.OpenAquariumID));
|
||||
return;
|
||||
}
|
||||
|
||||
//homeCanvasGroup.blocksRaycasts = false;
|
||||
//ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
||||
//bool isCanEnter = await loadResourceService.Load("FishingAquariumAct");
|
||||
//homeCanvasGroup.blocksRaycasts = true;
|
||||
//if (isCanEnter)
|
||||
//{
|
||||
EnterGame();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
||||
// panel.GetComponent<CloudTransitionPanel>().SetBtn(true, EnterGame);
|
||||
//}
|
||||
}
|
||||
void EnterGame()
|
||||
{
|
||||
homeCanvasGroup.blocksRaycasts = false;
|
||||
if (data != null && !data.isHome && data.slotDatas != null)
|
||||
{
|
||||
FishingAquariumAct.CloudType = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
FishingAquariumAct.CloudType = 1;
|
||||
}
|
||||
GContext.Publish(new UnloadActToNextAct("FishingAquariumAct", UITypes.AquariumCloudPanel, 0.75f));
|
||||
homeCanvasGroup.blocksRaycasts = true;
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (!fishingEventData.IsAquariumOpen || data == null || isred)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DateTime dateTime = ZZTimeHelper.UtcNow();
|
||||
if (data.isHome || data.slotDatas == null)
|
||||
{
|
||||
IsHome(dateTime.UtcNowOffset());
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < slotDatas.Count; i++)
|
||||
{
|
||||
var slotData = slotDatas[i];
|
||||
var HatchTime = slotData.FishHatchTime();
|
||||
var FishGrowthTime = slotData.FishGrowthTime();
|
||||
bool isHatch = HatchTime < dateTime;
|
||||
if (isHatch)
|
||||
{
|
||||
//鱼鱼
|
||||
bool growth = FishGrowthTime < dateTime;
|
||||
//检查是否受伤
|
||||
//正常的成长时间 自然时间+加速成长-总恢复时间
|
||||
float normalH = (float)(dateTime - HatchTime).TotalHours + slotData.accelerationGrowth - slotData.allRecoveryTime;
|
||||
|
||||
float injuryH = slotData.injuryGrowthTime;
|
||||
|
||||
//受伤时的成长进度大于正常的成长进度=还没恢复
|
||||
if (growth && injuryH < normalH)
|
||||
{
|
||||
//成熟并且没有受伤
|
||||
ShowRed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user