83 lines
2.0 KiB
C#
83 lines
2.0 KiB
C#
using cfg;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class LuckyTaskBtn : MonoBehaviour, IUIRedPoint
|
|
{
|
|
Button btn;
|
|
ILuckyTaskUIGetData model;
|
|
|
|
public string key;
|
|
public GameObject redPoint;
|
|
public GameObject redpoint_big;
|
|
public TMP_Text text_redpoint_big;
|
|
void Awake()
|
|
{
|
|
btn = GetComponent<Button>();
|
|
btn.onClick.AddListener(OnClick);
|
|
}
|
|
public void Init(ILuckyTaskUIGetData model, string key)
|
|
{
|
|
this.model = model;
|
|
this.key = key;
|
|
SetKey();
|
|
}
|
|
async void OnClick()
|
|
{
|
|
if (model != null)
|
|
{
|
|
GameObject taskPanelName = await UIManager.Instance.ShowUI(new UIType(model.TaskPanelName));
|
|
if (taskPanelName != null)
|
|
{
|
|
var panel = taskPanelName.GetComponent<LuckyTaskPanel>();
|
|
if (panel != null)
|
|
{
|
|
panel.Init(model);
|
|
int count = RedPointManager.Instance.GetRedPointCount(key);
|
|
RedPointManager.Instance.SetRedPointState(key, count > 0, count);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (!string.IsNullOrEmpty(key))
|
|
{
|
|
RedPointManager.Instance.RemoveRedPoint(key);
|
|
key = "";
|
|
}
|
|
}
|
|
public void SetKey()
|
|
{
|
|
RedPointManager.Instance.AddRedPoint(key, this);
|
|
SetRedPointState(RedPointManager.Instance.GetRedPointState(key));
|
|
}
|
|
|
|
public void SetRedPointState(bool state)
|
|
{
|
|
int count = RedPointManager.Instance.GetRedPointCount(key);
|
|
if (count > 1)
|
|
{
|
|
redpoint_big.SetActive(true);
|
|
if (count > 99)
|
|
{
|
|
text_redpoint_big.text = "99+";
|
|
}
|
|
else
|
|
{
|
|
text_redpoint_big.text = count.ToString();
|
|
}
|
|
state = false;
|
|
|
|
}
|
|
else
|
|
{
|
|
redpoint_big.SetActive(false);
|
|
}
|
|
redPoint.SetActive(state);
|
|
}
|
|
}
|