备份CatanBuilding瘦身独立工程
This commit is contained in:
107
Assets/Scripts/UI/Home/HomeBuffItem.cs
Normal file
107
Assets/Scripts/UI/Home/HomeBuffItem.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using asap.core;
|
||||
using GameCore;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class HomeBuffItem : MonoBehaviour
|
||||
{
|
||||
Button btn_buff;
|
||||
TMP_Text buff_time;
|
||||
Image buff_icon;
|
||||
Timer buff_timer;
|
||||
|
||||
public FishBuffTimeData buffTimeData;
|
||||
cfg.FishBuff buff;
|
||||
//buff_tips tips_buff;
|
||||
private void Init()
|
||||
{
|
||||
btn_buff = GetComponent<Button>();
|
||||
btn_buff.onClick.AddListener(OnClick);
|
||||
}
|
||||
public void InitPanel(FishBuffTimeData buffTimeData, string iconName, RectTransform rectTransform)
|
||||
{
|
||||
this.buffTimeData = buffTimeData;
|
||||
buff_time = transform.Find("Ani_Container/text_time").GetComponent<TMP_Text>();
|
||||
buff_icon = transform.Find("Ani_Container/icon").GetComponent<Image>();
|
||||
if (rectTransform != null)
|
||||
{
|
||||
RectTransform rect = buff_icon.GetComponent<RectTransform>();
|
||||
rect.anchoredPosition = rectTransform.anchoredPosition;
|
||||
rect.sizeDelta = rectTransform.sizeDelta;
|
||||
}
|
||||
InitBuff(iconName);
|
||||
}
|
||||
async void OnClick()
|
||||
{
|
||||
GameObject go = await UIManager.Instance.ShowUI(UITypes.FishingBuffInfoPopupPanel);
|
||||
FishingBuffInfoPopupPanel fishingBuffInfoPopupPanel = go.GetComponent<FishingBuffInfoPopupPanel>();
|
||||
fishingBuffInfoPopupPanel.InitPanel(buffTimeData);
|
||||
//item_tips _common_tips = await item_tips.Show();
|
||||
//if (_common_tips == null)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
//tips_buff = _common_tips.ShowBuff(transform.position, buff);
|
||||
}
|
||||
async void PlayBuff()
|
||||
{
|
||||
buffTimeData.isEnd = buffTimeData.addDown == 0;
|
||||
if (buffTimeData.isEnd)
|
||||
{
|
||||
btn_buff.gameObject.SetActive(false);
|
||||
GContext.Publish(new EventHomeBuffPanelRefresh());
|
||||
}
|
||||
await Awaiters.Seconds(1f);
|
||||
GContext.Publish(new BuffChangeEvent());
|
||||
}
|
||||
void InitBuff(string iconName)
|
||||
{
|
||||
if (btn_buff == null)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
btn_buff.gameObject.SetActive(buffTimeData != null);
|
||||
if (buffTimeData != null)
|
||||
{
|
||||
buff = GContext.container.Resolve<cfg.Tables>().TbFishBuff.GetOrDefault(buffTimeData.buffID);
|
||||
if (string.IsNullOrEmpty(iconName))
|
||||
{
|
||||
GContext.container.Resolve<IUIService>().SetImageSprite(buff_icon, buff.Icon);
|
||||
}
|
||||
else
|
||||
{
|
||||
GContext.container.Resolve<IUIService>().SetImageSprite(buff_icon, iconName);
|
||||
}
|
||||
var buffTime = buffTimeData.buffEndTime - ZZTimeHelper.UtcNow().UtcNowOffset();
|
||||
buff_timer?.Cancel();
|
||||
buffTime.Add(TimeSpan.FromSeconds(-buffTimeData.addDown));
|
||||
buff_time.text = ConvertTools.ConvertTime2(buffTime);
|
||||
|
||||
double seconds = buffTime.TotalSeconds;
|
||||
buff_timer = this.AttachTimer((float)seconds,
|
||||
() => { PlayBuff(); },
|
||||
(elapsed) =>
|
||||
{
|
||||
if (buffTimeData.isEnd)
|
||||
{
|
||||
buff_timer?.Cancel();
|
||||
PlayBuff();
|
||||
return;
|
||||
}
|
||||
TimeSpan now = buffTimeData.buffEndTime - ZZTimeHelper.UtcNow().UtcNowOffset();
|
||||
now.Add(TimeSpan.FromSeconds(-buffTimeData.addDown));
|
||||
buff_time.text = ConvertTools.ConvertTime2(now);
|
||||
|
||||
}, useRealTime: true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
buff_timer?.Cancel();
|
||||
buff_timer = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user