126 lines
4.0 KiB
C#
126 lines
4.0 KiB
C#
//锻刀大赛收集
|
|
//
|
|
|
|
using System.Threading.Tasks;
|
|
using asap.core;
|
|
using DG.Tweening;
|
|
using EventCubeMelt;
|
|
using EventCubeMelt.Data;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace EventCubeMelt.UI
|
|
{
|
|
public class CubeMeltCollectItems : MonoBehaviour
|
|
{
|
|
//
|
|
private Image _collectIcon;
|
|
|
|
private Image _bar;
|
|
|
|
private TMP_Text _textProgress;
|
|
|
|
// 进度闪光刷新
|
|
private Transform _fxRefresh;
|
|
|
|
private Transform _received;
|
|
|
|
#region Data
|
|
private EventCubeMeltManager _thisEventManager;
|
|
private EventCubeMeltData _thisEventData;
|
|
|
|
private int CurrentItemId { get; set; }
|
|
|
|
private int CurrentItemCount { get; set; }
|
|
|
|
|
|
#endregion
|
|
|
|
#region 周期函数
|
|
private void Awake()
|
|
{
|
|
_thisEventManager = GContext.container.Resolve<EventCubeMeltManager>();
|
|
_thisEventData = _thisEventManager.EventData;
|
|
|
|
_bar = transform.Find("image_progress").GetComponent<Image>();
|
|
_collectIcon = transform.Find("collect_icon").GetComponent<Image>();
|
|
_textProgress = transform.Find("text_progress").GetComponent<TMP_Text>();
|
|
_fxRefresh = transform.Find("fx_ui_event_cubemelt_refresh");
|
|
_received = transform.Find("received");
|
|
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
public RectTransform GetAniTransform()
|
|
{
|
|
return (RectTransform)_collectIcon.transform;
|
|
}
|
|
|
|
//
|
|
public void InitWithData(CollectItem item)
|
|
{
|
|
ELog("InitWithData-> ");
|
|
var uiService = GContext.container.Resolve<IUIService>();
|
|
var icon = _thisEventManager.GetCollectIconById(item.ItemTrueId);
|
|
uiService.SetImageSprite(_collectIcon, icon);
|
|
_textProgress.text = $"{item.Count}/{item.MaxCount}";
|
|
_bar.fillAmount = item.Count * 1f / item.MaxCount;
|
|
_received?.gameObject.SetActive(item.Count == item.MaxCount);
|
|
CurrentItemCount = item.Count;
|
|
CurrentItemId = item.ItemId;
|
|
|
|
}
|
|
|
|
private readonly float _duration = 0.5f * 0.01f;
|
|
private readonly float _fxRefreshDuration = 0.8f;
|
|
public async Task UpdateCollectItem(CollectItem item)
|
|
{
|
|
ELog("UpdateCollectItem-> ");
|
|
if (item.ItemId == CurrentItemId && item.Count == CurrentItemCount)
|
|
return;
|
|
|
|
var uiService = GContext.container.Resolve<IUIService>();
|
|
var icon = _thisEventManager.GetCollectIconById(item.ItemTrueId);
|
|
await uiService.SetImageSprite(_collectIcon, icon);
|
|
|
|
var lastFillAmount = _bar.fillAmount;
|
|
var fillAmount = item.Count * 1f / item.MaxCount;
|
|
var df = _duration * 100 * (fillAmount - lastFillAmount);
|
|
ELog($"UpdateCollectItem-> {df} {lastFillAmount} {fillAmount} {fillAmount - lastFillAmount}");
|
|
CurrentItemCount = item.Count;
|
|
CurrentItemId = item.ItemId;
|
|
_bar.DOFillAmount(fillAmount, df).OnComplete(() =>
|
|
{
|
|
_received?.gameObject.SetActive(item.Count == item.MaxCount);
|
|
});
|
|
|
|
_textProgress.text = $"{item.Count}/{item.MaxCount}";
|
|
// await Awaiters.Seconds(df);
|
|
_ = await RunFxRefresh();
|
|
}
|
|
|
|
private async Task<bool> RunFxRefresh()
|
|
{
|
|
_fxRefresh.gameObject.SetActive(true);
|
|
await Awaiters.Seconds(_fxRefreshDuration);
|
|
_fxRefresh.gameObject.SetActive(false);
|
|
ELog("RunFxRefresh Finish");
|
|
return true;
|
|
}
|
|
|
|
private static void ELog(string message)
|
|
{
|
|
#if UNITY_EDITOR
|
|
if (!EventCubeMeltLogPolicy.EnableELog) return;
|
|
Debug.Log($"<color=orange> CubeMeltCollectItems => {message} </color>");
|
|
#endif
|
|
}
|
|
}
|
|
} |