备份CatanBuilding瘦身独立工程
This commit is contained in:
168
Assets/Scripts/UI/RewardPopup/RewardPopupBase.cs
Normal file
168
Assets/Scripts/UI/RewardPopup/RewardPopupBase.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
using asap.core;
|
||||
using DG.Tweening;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
public class ShowRewardPopupTop
|
||||
{
|
||||
public bool isHide;
|
||||
public bool isShow;
|
||||
}
|
||||
|
||||
public class RewardPopupBase : RewardPopupBar
|
||||
{
|
||||
public GameObject top_area;
|
||||
public TMP_Text text_gold;
|
||||
public TMP_Text text_energy;
|
||||
public TMP_Text txt_diamond;
|
||||
int Energy;
|
||||
int curDiamond;
|
||||
ulong Gold;
|
||||
IDisposable disposable;
|
||||
protected bool isShowTop = false;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
disposable = GContext.OnEvent<ResAddEvent>().Subscribe(x =>
|
||||
{
|
||||
NumPlay(x.id, x.addCount);
|
||||
});
|
||||
}
|
||||
public void InitResource(List<ItemData> itemDatas)
|
||||
{
|
||||
ShowRewardPopupTop showRewardPopupTop = new ShowRewardPopupTop();
|
||||
GContext.Publish(showRewardPopupTop);
|
||||
top_area.SetActive(false);
|
||||
if (showRewardPopupTop.isHide && !showRewardPopupTop.isShow)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Energy = GContext.container.Resolve<PlayerData>().Energy;
|
||||
Gold = GContext.container.Resolve<PlayerData>().gold;
|
||||
curDiamond = GContext.container.Resolve<PlayerData>().diamond;
|
||||
bool isShow = ShowItemCount(itemDatas);
|
||||
if (isShow)
|
||||
{
|
||||
isShowTop = true;
|
||||
top_area.SetActive(true);
|
||||
text_energy.text = ConvertTools.GetNumberString2(Energy);
|
||||
text_gold.text = ConvertTools.GetNumberString2(Gold);
|
||||
txt_diamond.text = ConvertTools.GetNumberString2(curDiamond);
|
||||
}
|
||||
}
|
||||
|
||||
void NumPlay(int id, int addCount)
|
||||
{
|
||||
if (id == 1002)
|
||||
{
|
||||
GoldAddAnim(addCount);
|
||||
}
|
||||
else if (id == 1001)
|
||||
{
|
||||
EnergyAddAnim(addCount);
|
||||
}
|
||||
else if (id == 1005)
|
||||
{
|
||||
DiamondAddAnim(addCount);
|
||||
}
|
||||
}
|
||||
void GoldAddAnim(float add)
|
||||
{
|
||||
DOTween.Kill("popup_text_gold");
|
||||
text_gold.text = ConvertTools.GetNumberString2(Gold);
|
||||
ulong playerGold = GContext.container.Resolve<PlayerData>().gold;
|
||||
ulong endGold = playerGold;
|
||||
if (add > 0)
|
||||
{
|
||||
var _endGold = Gold + (ulong)add;
|
||||
if (_endGold < playerGold)
|
||||
{
|
||||
endGold = _endGold;
|
||||
}
|
||||
}
|
||||
|
||||
float progress = 0;
|
||||
ulong cur_glod = Gold;
|
||||
Gold = endGold;
|
||||
if (endGold < cur_glod)
|
||||
{
|
||||
ulong addGold = cur_glod - endGold;
|
||||
DOTween.To(() => progress, x => progress = x, 1, 1f).OnUpdate(() =>
|
||||
{
|
||||
ulong gold = (ulong)(addGold * progress);
|
||||
if (gold > cur_glod)
|
||||
{
|
||||
gold = cur_glod;
|
||||
}
|
||||
text_gold.text = ConvertTools.GetNumberString2(cur_glod - gold);
|
||||
}).SetId("popup_text_gold");
|
||||
}
|
||||
else if (endGold > cur_glod)
|
||||
{
|
||||
ulong addGold = endGold - cur_glod;
|
||||
DOTween.To(() => progress, x => progress = x, 1, 1f).OnUpdate(() =>
|
||||
{
|
||||
text_gold.text = ConvertTools.GetNumberString2(cur_glod + (ulong)(addGold * progress));
|
||||
}).SetId("popup_text_gold");
|
||||
}
|
||||
}
|
||||
void EnergyAddAnim(float add)
|
||||
{
|
||||
DOTween.Kill("popup_text_energy");
|
||||
text_energy.text = ConvertTools.GetNumberString2(Energy);
|
||||
int EndEnergy = Energy + (int)add;
|
||||
int curEnergy = Energy;
|
||||
Energy = EndEnergy;
|
||||
DOTween.To(() => curEnergy, x => curEnergy = x, EndEnergy, 1f).OnUpdate(() =>
|
||||
{
|
||||
text_energy.text = ConvertTools.GetNumberString2(curEnergy);
|
||||
}).SetId("popup_text_energy");
|
||||
}
|
||||
void DiamondAddAnim(float add)
|
||||
{
|
||||
DOTween.Kill("popup_text_diamond");
|
||||
txt_diamond.text = ConvertTools.GetNumberString2(curDiamond);
|
||||
var EndDiamond = curDiamond + (int)add;
|
||||
DOTween.To(() => curDiamond, x => curDiamond = x, EndDiamond, 1f).OnUpdate(() =>
|
||||
{
|
||||
txt_diamond.text = ConvertTools.GetNumberString2(curDiamond);
|
||||
}).SetId("popup_text_diamond").OnComplete(() => txt_diamond.text = ConvertTools.GetNumberString2(EndDiamond));
|
||||
}
|
||||
|
||||
|
||||
bool ShowItemCount(List<ItemData> itemDatas)
|
||||
{
|
||||
bool isShow = false;
|
||||
if (itemDatas != null)
|
||||
{
|
||||
for (int i = itemDatas.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (itemDatas[i].id == 1001)
|
||||
{
|
||||
Energy = (int)itemDatas[i].curCount;
|
||||
isShow = true;
|
||||
}
|
||||
else if (itemDatas[i].id == 1002)
|
||||
{
|
||||
Gold = (ulong)itemDatas[i].curCount;
|
||||
isShow = true;
|
||||
}
|
||||
else if (itemDatas[i].id == 1005)
|
||||
{
|
||||
curDiamond = (int)itemDatas[i].curCount;
|
||||
isShow = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isShow;
|
||||
}
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
disposable?.Dispose();
|
||||
disposable = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user