备份CatanBuilding瘦身独立工程
This commit is contained in:
124
Assets/Scripts/MiniBP/UI/HomeBtnMiniBP.cs
Normal file
124
Assets/Scripts/MiniBP/UI/HomeBtnMiniBP.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using asap.core;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class HomeBtnMiniBP : EventButtonResource, IUIRedPoint
|
||||
{
|
||||
public const string redKey = "MiniBP";
|
||||
public MiniBattlePassType Type = MiniBattlePassType.LuckMagic;
|
||||
MiniBattlePassDataModel miniBP;
|
||||
Image icon;
|
||||
Button btn;
|
||||
TMP_Text text_time;
|
||||
GameObject redpoint;
|
||||
|
||||
IDisposable timerDisposable;
|
||||
private void Awake()
|
||||
{
|
||||
miniBP = GContext.container.Resolve<MiniBattlePassDataProvider>().GetModel(Type);
|
||||
icon = transform.Find("icon").GetComponent<Image>();
|
||||
text_time = transform.Find("text_time").GetComponent<TMP_Text>();
|
||||
btn = GetComponent<Button>();
|
||||
redpoint = transform.Find("redpoint").gameObject;
|
||||
if (!miniBP.IsShow() || miniBP.IsDone())
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
CheckResource(new List<string>() { miniBP.PanelName, miniBP.Icon });
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
btn.onClick.AddListener(OnClickIn);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ShowTimer();
|
||||
RedPointManager.Instance.AddRedPoint(redKey + Type, this);
|
||||
SetRedPointState(RedPointManager.Instance.GetRedPointState(redKey + Type));
|
||||
}
|
||||
|
||||
|
||||
public void SetRedPointState(bool state)
|
||||
{
|
||||
redpoint.SetActive(state);
|
||||
|
||||
}
|
||||
|
||||
void OnClickIn()
|
||||
{
|
||||
UIManager.Instance.ShowUILoad(new UIType(miniBP.PanelName));
|
||||
}
|
||||
|
||||
void ShowTimer()
|
||||
{
|
||||
//剩余时间
|
||||
if (timerDisposable != null)
|
||||
{
|
||||
timerDisposable.Dispose();
|
||||
timerDisposable = null;
|
||||
}
|
||||
TimeSpan duration = miniBP.endTime - ZZTimeHelper.UtcNow();
|
||||
text_time.text = ConvertTools.ConvertTime2(duration);
|
||||
timerDisposable = Observable.Interval(TimeSpan.FromSeconds(1)).Subscribe(UpdateTimer);
|
||||
}
|
||||
public void SetShow()
|
||||
{
|
||||
miniBP = GContext.container.Resolve<MiniBattlePassDataProvider>().GetModel(Type);
|
||||
if (miniBP.IsShow() && !miniBP.IsDone())
|
||||
{
|
||||
ShowTimer();
|
||||
gameObject.SetActive(true);
|
||||
CheckResource(new List<string>() { miniBP.PanelName, miniBP.Icon });
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTimer(long _ = 0L)
|
||||
{
|
||||
text_time.text = ConvertTools.ConvertTime2(miniBP.endTime - ZZTimeHelper.UtcNow());
|
||||
if (!miniBP.IsShow())
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
protected void Refresh()
|
||||
{
|
||||
if (timerDisposable != null)
|
||||
{
|
||||
timerDisposable.Dispose();
|
||||
timerDisposable = null;
|
||||
}
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
RedPointManager.Instance.RemoveRedPoint(redKey + Type);
|
||||
|
||||
if (timerDisposable != null)
|
||||
{
|
||||
timerDisposable.Dispose();
|
||||
timerDisposable = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLoadEventResource()
|
||||
{
|
||||
miniBP = GContext.container.Resolve<MiniBattlePassDataProvider>().GetModel(Type);
|
||||
if (miniBP.IsShow() && !miniBP.IsDone())
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
IUIService uIService = GContext.container.Resolve<IUIService>();
|
||||
uIService.SetImageSprite(icon, miniBP.Icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user