99 lines
2.4 KiB
C#
99 lines
2.4 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIRedPoint : MonoBehaviour, IUIRedPoint
|
|
{
|
|
public string key;
|
|
public Image image;
|
|
public GameObject redPoint;
|
|
public GameObject redpoint_big;
|
|
public TMP_Text text_redpoint_big;
|
|
|
|
private void Awake()
|
|
{
|
|
if (string.IsNullOrEmpty(key))
|
|
{
|
|
return;
|
|
}
|
|
RedPointManager.Instance.AddRedPoint(key, this);
|
|
}
|
|
public void SetKey(string _key)
|
|
{
|
|
if (!string.IsNullOrEmpty(key))
|
|
{
|
|
RedPointManager.Instance.RemoveRedPoint(key);
|
|
}
|
|
key = _key;
|
|
RedPointManager.Instance.AddRedPoint(key, this);
|
|
if (redPoint != null)
|
|
{
|
|
redPoint.SetActive(RedPointManager.Instance.GetRedPointState(key));
|
|
}
|
|
if (image != null)
|
|
{
|
|
image.enabled = RedPointManager.Instance.GetRedPointState(key);
|
|
}
|
|
}
|
|
private void OnEnable()
|
|
{
|
|
if (string.IsNullOrEmpty(key))
|
|
{
|
|
return;
|
|
}
|
|
SetRedPointState(RedPointManager.Instance.GetRedPointState(key));
|
|
}
|
|
public void SetRedPointState(bool state)
|
|
{
|
|
if (string.IsNullOrEmpty(key))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (redpoint_big != null && text_redpoint_big != null)
|
|
{
|
|
if (!state)
|
|
{
|
|
redpoint_big.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
if (redPoint != null)
|
|
{
|
|
redPoint.SetActive(state);
|
|
}
|
|
if (image != null)
|
|
{
|
|
image.enabled = state;
|
|
}
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
if (string.IsNullOrEmpty(key))
|
|
{
|
|
return;
|
|
}
|
|
RedPointManager.Instance.RemoveRedPoint(key);
|
|
}
|
|
}
|