60 lines
1.5 KiB
C#
60 lines
1.5 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace UVC.Factory.Util
|
|
{
|
|
public class AlarmBadge : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private RectTransform badgeRectTransform;
|
|
[SerializeField]
|
|
private TextMeshProUGUI badgeText;
|
|
[SerializeField]
|
|
private int badgeCount = 0;
|
|
public int BadgeCount
|
|
{
|
|
get => badgeCount;
|
|
set
|
|
{
|
|
if (badgeCount == value || value < 0) return;
|
|
badgeCount = value;
|
|
SetBadgeCount(badgeCount);
|
|
}
|
|
}
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
if (badgeRectTransform == null)
|
|
{
|
|
badgeRectTransform = GetComponent<RectTransform>();
|
|
}
|
|
if (badgeText == null)
|
|
{
|
|
badgeText = GetComponentInChildren<TextMeshProUGUI>();
|
|
}
|
|
SetBadgeCount(badgeCount);
|
|
}
|
|
|
|
private void SetBadgeCount(int count)
|
|
{
|
|
if (count <= 0)
|
|
{
|
|
badgeRectTransform.gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
badgeText.text = count.ToString();
|
|
badgeRectTransform.gameObject.SetActive(true);
|
|
// 숫자 크기에 따라 badgeText 크기 조정
|
|
if (count > 999)
|
|
{
|
|
badgeText.text = "999+";
|
|
}
|
|
else
|
|
{
|
|
badgeText.text = count.ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|