先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
307 lines
13 KiB
C#
307 lines
13 KiB
C#
using UnityEngine.UI;
|
|
using game;
|
|
using asap.core;
|
|
using GameCore;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using cfg;
|
|
using DG.Tweening;
|
|
using UniRx;
|
|
|
|
//using System.Threading;
|
|
public class CampSkyscraperPanel : BasePanel
|
|
{
|
|
private Button _btnClose, _btnLeft, _btnConstruct, _btnInfo, _btnConstructGray;
|
|
//public Action OnClickConstruct, OnClickBtnClose;
|
|
public GameObject fxRating, goCombo;
|
|
private TMP_Text _textPrice, _textIBLvl, _textStepProgress, _textPriceGray, _comboText1, _comboText2, _comboText3;
|
|
TMP_Text text_cost_buff, text_old;//, text_cost_buffGray, text_oldGray;
|
|
private InfiniteBuildingData _ibd;
|
|
private ulong _price;
|
|
private Image _bar;
|
|
private RewardItemNew _reward, _flyMoney;
|
|
private Tables _tables;
|
|
private PlayerData _pd;
|
|
private PlayerItemData _pid;
|
|
private Animation _rewardAni, _lvlUpAni;
|
|
private TbConstructionInfiniteReward _rewardTable;
|
|
private EventAggregator _eventAggregator;
|
|
CanvasGroup canvasGroup;
|
|
private void Awake()
|
|
{
|
|
//Debug.Log($"<color=red>UI thread id: {Thread.CurrentThread.ManagedThreadId}</color>");
|
|
_btnClose = transform.Find("safearea/DownPanel/btn_close").GetComponent<Button>();
|
|
_btnLeft = transform.Find("safearea/DownPanel/btn_left").GetComponent<Button>();
|
|
_btnConstruct = transform.Find("safearea/DownPanel/btn_construct").GetComponent<Button>();
|
|
_btnConstructGray = transform.Find("safearea/DownPanel/btn_construct_gray").GetComponent<Button>();
|
|
fxRating = transform.Find("safearea/MiddlePanel/FX_info_piercing").gameObject;
|
|
_textPrice = transform.Find("safearea/DownPanel/btn_construct/text_cost").GetComponent<TMP_Text>();
|
|
_textPriceGray = transform.Find("safearea/DownPanel/btn_construct_gray/text_cost").GetComponent<TMP_Text>();
|
|
|
|
text_cost_buff = transform.Find("safearea/DownPanel/btn_construct/text_cost_buff").GetComponent<TMP_Text>();
|
|
text_old = transform.Find("safearea/DownPanel/btn_construct/text_cost_buff/text_old").GetComponent<TMP_Text>();
|
|
|
|
//text_cost_buffGray = transform.Find("safearea/DownPanel/btn_construct_gray/text_cost_buff").GetComponent<TMP_Text>();
|
|
//text_oldGray = transform.Find("safearea/DownPanel/btn_construct_gray/text_cost_buff/text_old").GetComponent<TMP_Text>();
|
|
|
|
_textIBLvl = transform.Find("top_area/level/icon_grade/text_grade").GetComponent<TMP_Text>();
|
|
_bar = transform.Find("safearea/MiddlePanel/skyscraper_target/bar").GetComponent<Image>();
|
|
_reward = transform.Find("safearea/MiddlePanel/skyscraper_target/reward").GetComponent<RewardItemNew>();
|
|
_btnInfo = transform.Find("top_area/level").GetComponent<Button>();
|
|
_textStepProgress = transform.Find("safearea/MiddlePanel/skyscraper_target/text_progress").GetComponent<TMP_Text>();
|
|
_rewardAni = transform.Find("safearea/MiddlePanel/skyscraper_target").GetComponent<Animation>();
|
|
//_lvlUpAni = transform.Find("fx_anim_campskyscraper_levelup_d_01")
|
|
_lvlUpAni = transform.Find("top_area/particle/fx_ui_campskyscraper_levelup_01 1").GetComponent<Animation>();
|
|
_flyMoney = transform.Find("RewardFlyPanel/reward").GetComponent<RewardItemNew>();
|
|
_pd = GContext.container.Resolve<PlayerData>();
|
|
_tables = GContext.container.Resolve<Tables>();
|
|
_pid = GContext.container.Resolve<PlayerItemData>();
|
|
_rewardTable = GContext.container.Resolve<Tables>().TbConstructionInfiniteReward;
|
|
goCombo = transform.Find("safearea/MiddlePanel/combo").gameObject;
|
|
_comboText1 = goCombo.transform.Find("text_num1").GetComponent<TMP_Text>();
|
|
_comboText2 = goCombo.transform.Find("text_num2").GetComponent<TMP_Text>();
|
|
_comboText3 = goCombo.transform.Find("text_num3").GetComponent<TMP_Text>();
|
|
canvasGroup = transform.GetComponent<CanvasGroup>();
|
|
}
|
|
protected override void Start()
|
|
{
|
|
//GContext.container.Resolve<CampData>().IsCanSkyscraper
|
|
//建造按钮是否置灰 !IsCanSkyscraper
|
|
bool t = GContext.container.Resolve<CampDataMM>().IsCanSkyscraper;
|
|
//t = false;
|
|
_btnConstruct.gameObject.SetActive(t);
|
|
_btnConstructGray.gameObject.SetActive(!t);
|
|
//Init();
|
|
base.Start();
|
|
GContext.OnEvent<RestartShowHomeUIEvent>().Subscribe(_ =>
|
|
{
|
|
canvasGroup.alpha = 1;
|
|
canvasGroup.blocksRaycasts = true;
|
|
}).AddTo(disposables);
|
|
|
|
GContext.OnEvent<HideHomePanelEvent>().Subscribe(_ =>
|
|
{
|
|
canvasGroup.alpha = 0;
|
|
canvasGroup.blocksRaycasts = false;
|
|
}).AddTo(disposables);
|
|
GContext.OnEvent<ChangeLanguageEvent>().Subscribe(OnChangeLanguage).AddTo(disposables);
|
|
}
|
|
private void OnClickClose()
|
|
{
|
|
//OnClickBtnClose?.Invoke();
|
|
GContext.Publish(new UnloadActToNextAct());
|
|
}
|
|
private int target;
|
|
public void Init(InfiniteBuildingData ibd, EventAggregator ea)
|
|
{
|
|
_ibd = ibd;
|
|
|
|
int price = SetPrice();
|
|
|
|
_textPriceGray.text = ConvertTools.GetNumberString(price);
|
|
_textIBLvl.text = _ibd.Lvl.ToString();
|
|
target = _tables.TbConstructionInfiniteReward[_ibd.StepLvl].Step;
|
|
_textStepProgress.text = LocalizationMgr.GetFormatTextValue("UI_CampPanel_9", string.Format("{0}/{1}", _ibd.Step, target));
|
|
_bar.fillAmount = (float)_ibd.Step / (float)target;
|
|
_reward.SetData(_pid.GetItemDataOne(_rewardTable[_ibd.StepLvl].DropID));
|
|
_eventAggregator = ea;
|
|
}
|
|
|
|
void OnChangeLanguage(ChangeLanguageEvent changeLanguageEvent)
|
|
{
|
|
_textStepProgress.text = LocalizationMgr.GetFormatTextValue("UI_CampPanel_9", string.Format("{0}/{1}", _ibd.Step, target));
|
|
}
|
|
|
|
|
|
public async System.Threading.Tasks.Task<bool> UpdateUIWhenSuccess()
|
|
{
|
|
if (_ibd == null)
|
|
{
|
|
Debug.LogError("Infinite building data is null in UI sript.");
|
|
return false;
|
|
}
|
|
PlayLvlUpAnimation();
|
|
target = _rewardTable[_ibd.StepLvl].Step;
|
|
if (_ibd.Step < target)
|
|
{
|
|
_bar.DOFillAmount((float)_ibd.Step / (float)target, 0.5f).onComplete +=
|
|
() => _textStepProgress.text = LocalizationMgr.GetFormatTextValue("UI_CampPanel_9", string.Format("{0}/{1}", _ibd.Step, target));
|
|
SetPrice();
|
|
//_textStepProgress.text = string.Format("Step {0}/{1}", target, target);
|
|
return false;
|
|
}
|
|
_textStepProgress.text = LocalizationMgr.GetFormatTextValue("UI_CampPanel_9", string.Format("{0}/{1}", _ibd.Step, target));
|
|
await _bar.DOFillAmount(1, 0.5f).AsyncWaitForCompletion();
|
|
return true;
|
|
//step target achieved!!!
|
|
}
|
|
private async System.Threading.Tasks.Task PlayLvlUpAnimation()
|
|
{
|
|
_lvlUpAni.gameObject.SetActive(false);
|
|
_lvlUpAni.gameObject.SetActive(true);
|
|
await System.Threading.Tasks.Task.Delay(1000 * 55 / 60);
|
|
int lvl = int.Parse(_textIBLvl.text);
|
|
DOTween.To(() => lvl, value => lvl = value, _ibd.Lvl, 0.3f)
|
|
.OnUpdate(() => { _textIBLvl.text = lvl.ToString(); });
|
|
//_textIBLvl.text = _ibd.Lvl.ToString();
|
|
}
|
|
public async System.Threading.Tasks.Task ReceiveReward()
|
|
{
|
|
_rewardAni.Play("campskyscraper_target");
|
|
await System.Threading.Tasks.Task.Delay(1000 * 92 / 60);
|
|
int dropID = _rewardTable[_ibd.StepLvl].DropID;
|
|
_pid.AddItemByDrop(dropID, null, true);
|
|
GContext.Publish(new ShowData());
|
|
_eventAggregator.Publish(new EventInfiniteBuildingGetReward(dropID));
|
|
_bar.fillAmount = 0;
|
|
_ibd.Step -= target;
|
|
_ibd.StepLvl++;
|
|
_ibd.StepLvl = ((_ibd.StepLvl - 1) % _rewardTable.DataList.Count) + 1;
|
|
target = _rewardTable[_ibd.StepLvl].Step;
|
|
//Debug.Log($"<color=red>stepLvl: {_ibd.StepLvl}," +
|
|
// $"dropID: {_pid.GetItemDataOne(_rewardTable[_ibd.StepLvl].DropID)}</color>");
|
|
_reward.SetData(_pid.GetItemDataOne(_rewardTable[_ibd.StepLvl].DropID));
|
|
_textStepProgress.text = LocalizationMgr.GetFormatTextValue("UI_CampPanel_9", string.Format("{0}/{1}", _ibd.Step, target));
|
|
SetPrice();
|
|
|
|
_ibd.UploadData();
|
|
}
|
|
int SetPrice()
|
|
{
|
|
int price = _ibd.ConstructPrice;
|
|
var buffTimeData = GContext.container.Resolve<BuffDataCenter>().GetWeelyBuffTimeData<ConstructionCost>();
|
|
bool isConstructionCost = buffTimeData != null;
|
|
text_cost_buff.gameObject.SetActive(isConstructionCost);
|
|
_textPrice.gameObject.SetActive(!isConstructionCost);
|
|
if (isConstructionCost)
|
|
{
|
|
text_old.text = ConvertTools.GetNumberString(price);
|
|
_price = (ulong)(price * (1 - buffTimeData.Param));
|
|
text_cost_buff.text = ConvertTools.GetNumberString(_price);
|
|
}
|
|
else
|
|
{
|
|
_price = (ulong)price;
|
|
_textPrice.text = ConvertTools.GetNumberString(price);
|
|
}
|
|
return price;
|
|
}
|
|
async void InBuildAct()
|
|
{
|
|
var campData = GContext.container.Resolve<CampDataMM>();
|
|
ILoadResourceService loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
bool isCanEnter = await loadResourceService.Loads(campData.AllPrefabs);
|
|
if (isCanEnter)
|
|
{
|
|
GContext.Publish(new UnloadActToNextAct("BuildAct"));
|
|
}
|
|
else
|
|
{
|
|
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
panel.GetComponent<CloudTransitionPanel>().SetBtn(true, () => GContext.Publish(new UnloadActToNextAct("BuildAct")));
|
|
//var panel = await UIManager.Instance.ShowUI(UITypes.FishingDownLoadPopupPanel);
|
|
//panel.GetComponent<FishingDownLoadPopupPanel>().SetBtn(null, () => GContext.Publish(new UnloadActToNextAct("BuildAct")));
|
|
}
|
|
}
|
|
|
|
public void PlayComboFx(int comboCount)
|
|
{
|
|
if (comboCount <= 1)
|
|
return;
|
|
goCombo.SetActive(false);
|
|
switch (comboCount)
|
|
{
|
|
case > 10:
|
|
_comboText3.text = comboCount.ToString();
|
|
_comboText1.gameObject.SetActive(false);
|
|
_comboText2.gameObject.SetActive(false);
|
|
_comboText3.gameObject.SetActive(true);
|
|
break;
|
|
case > 5:
|
|
_comboText2.text = comboCount.ToString();
|
|
_comboText1.gameObject.SetActive(false);
|
|
_comboText2.gameObject.SetActive(true);
|
|
_comboText3.gameObject.SetActive(false);
|
|
break;
|
|
default:
|
|
_comboText1.text = comboCount.ToString();
|
|
_comboText1.gameObject.SetActive(true);
|
|
_comboText2.gameObject.SetActive(false);
|
|
_comboText3.gameObject.SetActive(false);
|
|
break;
|
|
}
|
|
goCombo.SetActive(true);
|
|
}
|
|
/// <summary>
|
|
/// Play the rating fx.
|
|
/// </summary>
|
|
/// <param name="rating">0 for nothing, 1 for good, 2 for fantastic.</param>
|
|
public void PlayRatingFx(int rating)
|
|
{
|
|
if (rating == 0)
|
|
return;
|
|
fxRating.gameObject.SetActive(false);
|
|
fxRating.transform.Find("1").gameObject.SetActive(rating == 2);
|
|
fxRating.transform.Find("2").gameObject.SetActive(rating == 1);
|
|
fxRating.gameObject.SetActive(true);
|
|
}
|
|
public async System.Threading.Tasks.Task PlayCashFlyAnimation(int count)
|
|
{
|
|
// PerfectAni.SetActive(false);
|
|
// PerfectAni.SetActive(true);
|
|
_flyMoney.gameObject.SetActive(true);
|
|
_flyMoney.SetRewardPopupData(new ItemData(1002, count));
|
|
_flyMoney.GetComponent<Animation>().Play("reward_common_open");
|
|
await System.Threading.Tasks.Task.Delay(16 * 1000 / 60);
|
|
_flyMoney.GetComponent<Animation>().Play("reward_common_close");
|
|
await System.Threading.Tasks.Task.Delay(16 * 1000 / 60);
|
|
await _flyMoney.ParticleAttractor();
|
|
_flyMoney.gameObject.SetActive(false);
|
|
GContext.Publish(new ResAddEvent(1002));
|
|
}
|
|
public void ActivateBtns()
|
|
{
|
|
//if (!_btnConstruct.gameObject.activeSelf)
|
|
// return;
|
|
|
|
_btnConstruct.onClick.AddListener(OnClickPlay);
|
|
_btnConstructGray.onClick.AddListener(
|
|
() => ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_77")));
|
|
_btnClose.onClick.AddListener(OnClickClose);
|
|
_btnLeft.onClick.AddListener(InBuildAct);
|
|
//_btnConstruct.onClick.AddListener(OnClickPlay);
|
|
_btnInfo.onClick.AddListener(() => UIManager.Instance.ShowUI(UITypes.CampInfoPanel));
|
|
}
|
|
public void DeactivateBtns()
|
|
{
|
|
_btnConstruct.onClick.RemoveAllListeners();
|
|
_btnConstructGray.onClick.RemoveAllListeners();
|
|
_btnClose.onClick.RemoveAllListeners();
|
|
_btnLeft.onClick.RemoveAllListeners();
|
|
_btnInfo.onClick.RemoveAllListeners();
|
|
}
|
|
private void OnClickPlay()
|
|
{
|
|
//Debug.Log("Play!!!!!!!!!!!");
|
|
_btnConstruct.gameObject.GetComponent<Animator>().Play("clicked");
|
|
if ((ulong)_pd.gold >= _price)
|
|
{
|
|
_btnConstruct.onClick.RemoveAllListeners();
|
|
_pd.SetGold(_pd.gold - _price);
|
|
GContext.Publish(new ResAddEvent(1002));
|
|
_eventAggregator.Publish(new EventInfiniteBuildingConstruct(_price));
|
|
}
|
|
else
|
|
{
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_CampPanel_8"));
|
|
}
|
|
}
|
|
#if UNITY_EDITOR
|
|
//private void OnGUI()
|
|
//{
|
|
// GUI.Box(new Rect(20, 110, 200, 20), _btnConstruct.isActiveAndEnabled.ToString());
|
|
//}
|
|
#endif
|
|
}
|
|
|