备份CatanBuilding瘦身独立工程
This commit is contained in:
98
Assets/Scripts/UIRedPoint/UIRedPoint.cs
Normal file
98
Assets/Scripts/UIRedPoint/UIRedPoint.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user