备份CatanBuilding瘦身独立工程
This commit is contained in:
255
Assets/Scripts/Aquarium/UI/AquariumSlot.cs
Normal file
255
Assets/Scripts/Aquarium/UI/AquariumSlot.cs
Normal file
@@ -0,0 +1,255 @@
|
||||
using asap.core;
|
||||
using DG.Tweening;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class AquariumSlot : MonoBehaviour
|
||||
{
|
||||
public Button btn_click;
|
||||
public Image icon_egg;
|
||||
public GameObject mask_fish;
|
||||
public Image icon_fish;
|
||||
public Image icon_rate;
|
||||
public GameObject selected;
|
||||
public GameObject done;
|
||||
public GameObject icon_hurt;
|
||||
public GameObject icon_killed;
|
||||
public GameObject icon_sold;
|
||||
public GameObject redpoint;
|
||||
public AquariumSlotData slotData;
|
||||
public Image bar;
|
||||
public Image bar_hurt;
|
||||
Action<AquariumSlot> onClick;
|
||||
Action onFishStateChange;
|
||||
public int index;
|
||||
/// <summary>
|
||||
/// 1 == egg 2 == fish 3 == done 4 == sell 5 == lose
|
||||
/// </summary>
|
||||
[HideInInspector]
|
||||
public int slotState = 0;
|
||||
AquariumManager AM;
|
||||
//private void Reset()
|
||||
//{
|
||||
// btn_click = GetComponent<Button>();
|
||||
// icon_egg = transform.Find("icon_egg").GetComponent<Image>();
|
||||
// mask_fish = transform.Find("mask_fish").gameObject;
|
||||
// icon_fish = transform.Find("mask_fish/icon_fish").GetComponent<Image>();
|
||||
// icon_rate = transform.Find("mask_fish/icon_rate").GetComponent<Image>();
|
||||
// selected = transform.Find("selected").gameObject;
|
||||
// done = transform.Find("mask_fish/done").gameObject;
|
||||
// icon_hurt = transform.Find("icon_hurt").gameObject;
|
||||
// icon_killed = transform.Find("icon_killed").gameObject;
|
||||
// icon_sold = transform.Find("icon_sold").gameObject;
|
||||
// redpoint = transform.Find("redpoint").gameObject;
|
||||
// bar = transform.Find("bg_bar/bar").GetComponent<Image>();
|
||||
// bar_hurt = transform.Find("bg_bar/bar_hurt").GetComponent<Image>();
|
||||
//}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
redpoint.SetActive(false);
|
||||
btn_click.onClick.AddListener(OnClick);
|
||||
}
|
||||
void OnClick()
|
||||
{
|
||||
//if (slotState == 4)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
onClick?.Invoke(this);
|
||||
}
|
||||
public void InitSlot(int index, AquariumSlotData slotData, Action<AquariumSlot> onClick, Action onFishStateChange)
|
||||
{
|
||||
AM = GContext.container.Resolve<AquariumManager>();
|
||||
this.index = index;
|
||||
this.slotData = slotData;
|
||||
this.onClick = onClick;
|
||||
this.onFishStateChange = onFishStateChange;
|
||||
SetState();
|
||||
InitBar();
|
||||
}
|
||||
public void SetState()
|
||||
{
|
||||
DateTime dateTime = ZZTimeHelper.UtcNow();
|
||||
var HatchTime = slotData.FishHatchTime();
|
||||
var FishGrowthTime = slotData.FishGrowthTime();
|
||||
bool isHatch = HatchTime < dateTime;
|
||||
TimeSpan offsetTime = new TimeSpan();
|
||||
bool isUpdate = false;
|
||||
done.gameObject.SetActive(false);
|
||||
icon_hurt.gameObject.SetActive(false);
|
||||
bar_hurt.gameObject.SetActive(false);
|
||||
icon_killed.gameObject.SetActive(false);
|
||||
bar.gameObject.SetActive(true);
|
||||
redpoint.SetActive(false);
|
||||
if (isHatch)
|
||||
{
|
||||
//鱼鱼
|
||||
slotState = 2;
|
||||
icon_egg.gameObject.SetActive(false);
|
||||
mask_fish.gameObject.SetActive(true);
|
||||
|
||||
bool growth = FishGrowthTime < dateTime;
|
||||
|
||||
List<AquariumResultData> aquariumReportDatas = AM.data.aquariumResultDatas;
|
||||
|
||||
//售卖或者丢失
|
||||
if (slotData.IsResult())
|
||||
{
|
||||
slotState = 4;
|
||||
//btn_click.enabled = false;
|
||||
done.gameObject.SetActive(true);
|
||||
icon_sold.gameObject.SetActive(true);
|
||||
bar.gameObject.SetActive(false);
|
||||
}
|
||||
else if (aquariumReportDatas[slotData.index].IsResult())
|
||||
{
|
||||
slotState = 5;
|
||||
icon_killed.gameObject.SetActive(true);
|
||||
done.gameObject.SetActive(true);
|
||||
bar.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
//检查是否受伤
|
||||
//正常的成长时间 自然时间+加速成长-总恢复时间
|
||||
float normalH = (float)(dateTime - HatchTime).TotalHours + slotData.accelerationGrowth - slotData.allRecoveryTime;
|
||||
|
||||
float injuryH = slotData.injuryGrowthTime;
|
||||
|
||||
//受伤时的成长进度大于正常的成长进度=还没恢复
|
||||
isUpdate = true;
|
||||
if (injuryH > normalH)
|
||||
{
|
||||
bar.gameObject.SetActive(false);
|
||||
bar_hurt.gameObject.SetActive(true);
|
||||
icon_hurt.gameObject.SetActive(true);
|
||||
offsetTime = dateTime.AddHours(injuryH - normalH) - dateTime;
|
||||
}
|
||||
else if (growth)
|
||||
{
|
||||
//成熟并且没有受伤
|
||||
slotState = 3;
|
||||
isUpdate = false;
|
||||
redpoint.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
bar_hurt.gameObject.SetActive(false);
|
||||
icon_hurt.gameObject.SetActive(false);
|
||||
offsetTime = FishGrowthTime - dateTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isUpdate = true;
|
||||
offsetTime = HatchTime - dateTime;
|
||||
//蛋蛋
|
||||
slotState = 1;
|
||||
icon_egg.gameObject.SetActive(true);
|
||||
mask_fish.gameObject.SetActive(false);
|
||||
done.gameObject.SetActive(false);
|
||||
}
|
||||
if (isUpdate)
|
||||
{
|
||||
StartCoroutine(UpdateTime((float)offsetTime.TotalSeconds));
|
||||
}
|
||||
}
|
||||
|
||||
void InitBar()
|
||||
{
|
||||
if (slotState == 5)
|
||||
{
|
||||
bar.fillAmount = 0;
|
||||
return;
|
||||
}
|
||||
if (slotState == 4)
|
||||
{
|
||||
bar.fillAmount = 0;
|
||||
return;
|
||||
}
|
||||
DateTime dateTime = ZZTimeHelper.UtcNow();
|
||||
|
||||
if (slotState == 1)
|
||||
{
|
||||
float time = (float)(dateTime - slotData.startTime).TotalHours + slotData.accelerationHatch;
|
||||
bar.fillAmount = time / slotData.hatchTime;
|
||||
return;
|
||||
}
|
||||
var StartTime = slotData.FishHatchTime();
|
||||
//正常的成长进度 自然时间+加速成长 - 全部恢复时间
|
||||
float normalH = (float)(dateTime - StartTime).TotalHours + slotData.accelerationGrowth - slotData.allRecoveryTime;
|
||||
//受伤时的成长进度
|
||||
float injuryH = slotData.injuryGrowthTime;
|
||||
|
||||
//受伤时的成长进度大于正常的成长进度
|
||||
float timeProgress = 1;
|
||||
if (injuryH > normalH)
|
||||
{
|
||||
bar_hurt.fillAmount = (injuryH - normalH) / slotData.growthTime;
|
||||
timeProgress = 0;// injuryH / slotData.growthTime;
|
||||
}
|
||||
else if (normalH < slotData.growthTime)
|
||||
{
|
||||
timeProgress = normalH / slotData.growthTime;
|
||||
}
|
||||
bar.fillAmount = timeProgress;
|
||||
}
|
||||
|
||||
public void UpdateBar(DateTime dateTime)
|
||||
{
|
||||
if (slotState == 5)
|
||||
{
|
||||
bar.fillAmount = 0;
|
||||
return;
|
||||
}
|
||||
if (slotState == 4)
|
||||
{
|
||||
//bar.DOFillAmount(1, 0.9f);
|
||||
bar.fillAmount = 0;
|
||||
return;
|
||||
}
|
||||
if (slotState == 1)
|
||||
{
|
||||
float time = (float)(dateTime - slotData.startTime).TotalHours + slotData.accelerationHatch;
|
||||
var fillAmount = time / slotData.hatchTime;
|
||||
bar.DOFillAmount(fillAmount, 0.9f);
|
||||
return;
|
||||
}
|
||||
var StartTime = slotData.FishHatchTime();
|
||||
//正常的成长进度 自然时间+加速成长 - 全部恢复时间
|
||||
float normalH = (float)(dateTime - StartTime).TotalHours + slotData.accelerationGrowth - slotData.allRecoveryTime;
|
||||
//受伤时的成长进度
|
||||
float injuryH = slotData.injuryGrowthTime;
|
||||
|
||||
//受伤时的成长进度大于正常的成长进度
|
||||
float timeProgress = 1;
|
||||
if (injuryH > normalH)
|
||||
{
|
||||
var fillAmount = (injuryH - normalH) / slotData.recoveryTime;
|
||||
bar_hurt.DOFillAmount(fillAmount, 0.9f);
|
||||
//timeProgress = injuryH / slotData.growthTime;
|
||||
bar.fillAmount = 0;
|
||||
}
|
||||
else if (normalH < slotData.growthTime)
|
||||
{
|
||||
timeProgress = normalH / slotData.growthTime;
|
||||
bar.DOFillAmount(timeProgress, 0.9f);
|
||||
}
|
||||
else
|
||||
{
|
||||
bar.DOFillAmount(timeProgress, 0.9f);
|
||||
}
|
||||
}
|
||||
IEnumerator UpdateTime(float s)
|
||||
{
|
||||
yield return new WaitForSeconds(s);
|
||||
//发送事件,状态修改
|
||||
onFishStateChange?.Invoke();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user